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.example
file in the root directory to.env
and 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.production
file to differentiate between development and production environments. With this setup,.env
will 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/subcommands
and create a new.mjs
file 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 theaddSubcommand
method.execute
: An async class method that is called when the subcommand is executed.
💡 The
execute
method in theCommand
class supports loading subcommands by default. You need to implement the logic yourself if your command overrides theexecute
method.
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
.mjs
file in thesrc/events/messageHandlers
directory - Inside your new message handler file, export a method with your custom logic.
- Your method needs to filter each message and return
null
when the message doesn't match your criteria, as every handler will be executed for every message.