A scalable Discord bot framework: easily expandable with modular components. This is a barebones template. If you want to see something more fleshed out, check out this translation bot fork.
- Install dependencies
yarn install
- Rename the
.env.examplefile in the root directory to.envand add your values. Every variable is required except forSENTRY_DSN, which is only required if you want to use Sentry for error reporting.- You can also create a
.env.productionfile to differentiate between development and production environments. With this setup,.envwill override any production values while in development.
- You can also create a
- Start the bot
- In production:
yarn start
- In development:
yarn dev
- In production:
- Invite the bot to your server. You can generate an invite link from the Discord Developer Portal.
Commands are defined in the src/commands directory. Each command is a class
that inherits from the Command class. The Command class provides a simple
interface for defining commands and subcommands.
To create a subcommand, you need to follow a few steps.
- Create a folder matching the base command's name in
src/commands/subcommandsand create a new.mjsfile matching the subcommand's name. - Inside your new subcommand file, export an object with:
data: An arrow method that is passed as an argument to theaddSubcommandmethod.execute: An async class method that is called when the subcommand is executed.
💡 The
executemethod in theCommandclass supports loading subcommands by default. You need to implement the logic yourself if your command overrides theexecutemethod.
Events are defined in the src/events directory. Each event is an object, not a
class. The execute method is called when the event is triggered.
The messageCreate event can dynamically load message handler modules. To
create a message handler:
- Create a new
.mjsfile in thesrc/events/messageHandlersdirectory - Inside your new message handler file, export a method with your custom logic.
- Your method needs to filter each message and return
nullwhen the message doesn't match your criteria, as every handler will be executed for every message.