This is a (still unfinished) Discord bot I work on sporadically to learn both Node.js and discord.js.
This project is pretty much a work in progress, going to be a "proof of concept" how a good internal structure of a Discord bot could look like. If you have any suggestions please do not hesitate to contact me: WRMSR#1337
on Discord (but please mention my bot, otherwise I won't accept you).
To invite this bot to your Discord server, click this link.
The easiest way to get this bot up and running is to deploy it via Docker (a Dockerfile is provided). However, it still needs an external PostgreSQL (with installed TimescaleDB addon - you need at least version 1.3.0
) and Redis instance. The bot has no problems with pgbouncer in transaction
pooling mode (if used). Although the bot uses the Sequelize ORM, because of the TimescaleDB dependency it is practically unable to run with another RDBMS vendor (for example MariaDB).
Redis Sentinel (for Redis HA) is supported via redis.sentinel.addresses
(comma separated servers) and redis.sentinel.name
setting key.
The bot's default configuration is in the settings.js file, however it is not recommended to change settings there, as they might get overwritten on the next git pull. To change settings, either use environment variables (best suited for Docker installations) or create a file named .env
in the bot's root directory and place the overwritten parameters there, as seen in the Twelve-Factor App methodology.
For example: To store your bot token, either pass the environment variable bot.token
containing the bot's token or insert bot.token=<token>
in the .env
file. The same goes for another example with the database password defined as database.password
.
If your database installation and bot config is done, you need to initialize the database: Running sequelize db:migrate
should do the trick (for Linux this would be node_modules/.bin/sequelize db:migrate
). This should be run on bot updates too, to keep up with the latest required database schema.
First off, you should be familiar with the discord.js documentation.
To see how commands, events, tasks or types are structured, view the documentation in their respective folders:
For the context object, see the context documentation.
- matmen for open-sourcing fbot and helping me out with some JavaScript questions
- NotSoSuper for letting me spam his Discord server for testing purposes (and actually promoting me to mod, lol)
- DBot for open-sourcing NotDBot
- The people behind discord.js Commando (I'm not actually using Commando, it just inspired me how to declare commands)