A simple Discord Bot template with prebuilt command and hook system for easier development and maintenance
- Create a repo using this template/clone this repo
- Run
npm install
ornpm ci
- Create a
.env
file with aDISCORD_TOKEN
[1] field - Modify the code as you wish
- Run
npm start
This template is completely unopinionated in everything related to deployment.
The simpler (yet expensive) way to deploy this bot is using services like Heroku, other alternative is to use a VPS from providers like OVH or Google Cloud.
In order to have a deployment interface and management service, you could use something like PM2.
In any case, the command to start the bot is npm start
, it is recommended to add a NODE_ENV
field on .env
with the value of PRODUCTION
.
There are 3 key folders, almost everything you are going to do is inside these folders:
-
bot
- Contains client options (client.json
) and command client options (info.json
). These files are used in the constructor ofEris.CommandClient
like the following:Eris.CommandClient(DISCORD_TOKEN, client.json, info.json)
-
commands
- Contains the source code to all the commands, the command prefixes cam be customized on theinfo.json
file. -
hooks
- Contains the source code of the hooks. The hooks exported from theindex.js
have a key (the hook event string), and a function/array of functions that are executed when this event is triggered. These files are used in theEris.CommandClient.on
function like the following:Eris.CommandClient.on(key, value)
, this is wrapped on afor...of
statement if the value is an array.
- Create a new JavaScript file on
data/commands
folder - Create a generator function (check example.js)
- Export a JSON object with: label, options and generator keys (check example.js)
- Import the object on index.js and add it to the
availableCommands
array
- Create a new JavaScript file on
data/hooks
folder - Create a function that will handle the hook and export it
- Import the function on index.js and add it to the
availableHooks
object, using as the key the desired event name
If you do not have, yet a bot created, you can check out the Discord documentation (or search online for a guide)