Discord-Bot-TypeScript-Template icon indicating copy to clipboard operation
Discord-Bot-TypeScript-Template copied to clipboard

Template Encourages too much Redundancy

Open Kaisarion opened this issue 3 years ago • 2 comments

start-bot.ts requires the importation of command classes through the index.ts.

then, there is a command array created:

 let commands: Command[] = [
        // Commands
       // Chat Commands
       // _Admin
        new CreateRoleCommand(),
        new DeleteRoleCommand(),

        // _Info
        new CreditsCommand(),
        new AddBotCommand(),

        // _Moderation
        new AssignRoleCommand(),
        new BanCommand(),

        new HelpCommand(),
        new StatusCommand(),

        // Message Context Commands
        new ViewDateSent(),

        // User Context Commands
        new ViewDateJoined(),

       // TODO: Add new commands here
    ]

You can see the problem if we have over 100 commands, the file would turn into 400-500 lines easily.

Any future dynamic solution to this? It leaves our hands tied.

Kaisarion avatar Nov 18 '22 20:11 Kaisarion

@Kaisarion One possible solution to this issue would be to organize the commands into different categories or modules, and then import each module separately. This would make the code more organized and easier to read and maintain. For example:

// Chat Commands import * as chatCommands from './chat-commands';

// Message Context Commands import * as messageCommands from './message-commands';

// User Context Commands import * as userCommands from './user-commands';

let commands: Command[] = [ // Chat Commands ...chatCommands.adminCommands, ...chatCommands.infoCommands, ...chatCommands.moderationCommands,

// Message Context Commands
...messageCommands.all,

// User Context Commands
...userCommands.all,

// TODO: Add new commands here

];

Alternatively, you could use an object to store the commands, where the keys represent the different categories or modules and the values are arrays of commands. This would allow you to easily access and use the commands in different parts of your code.

MagicPotato21 avatar Dec 11 '22 16:12 MagicPotato21

It would be nice to have it organized into modules. There's a lot of locations where things need to be added just to add a new command.

techguydave avatar Jul 18 '23 22:07 techguydave