A bot setup based on guide provided on https://discordjs.guide/ with autoloading new commands in addition.
Clone this repo
git clone git@github.com:Rantti/basic-discord-bot.gitInstall dependencies
npm installCreate .env file based on template and fill in variables inside.
cp .env.template .envBasically you need to fetch your bot token provided by discord from their applications management page. Select your bot application or create a new one. Then from the left sidebar from selected application select "Bot" under settings and reveal the token found there.
Run application:
node .For development you can use nodemon to reload app as you make changes to it:
npm run dev| Variable name | Description |
|---|---|
| TOKEN | Bot token assigned to your application |
| COMMAND_PREFIX | Prefix for commands to recognize commands designated for bot, defaults to "!" |
Currently only message-based commands are supported. You can create a new command under commands/message/-directory and the application will automatically load the new command.
module.exports = {
command: 'template',
description: 'Template command', // Description, used in "list" command.
callBack: function(message, args) {
// Your command logic here
},
};command- name of the command that needs to be sent for callback to be executeddescription- straightforward short description what the command does. Used currently by list command.callBack(message, args)- Executed callback.messagevariable is the Message class used by discord.js.argsis an array of words separated by empty space after the command in sent message.