KevinNovak / Discord-Bot-TypeScript-Template

Discord bot - A discord.js bot template written with TypeScript.
MIT License
477 stars 86 forks source link

Template Encourages too much Redundancy #56

Open Kaisarion opened 1 year ago

Kaisarion commented 1 year ago

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.

MagicPotato21 commented 1 year ago

@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.

techguydave commented 1 year ago

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.