Discord bot boiler-plate
MIT License
Inspired to create stand-alone boiler-plate after contributions I had made to a private bot repository from hailthekid
Bot
class.nodemon
restarts application automatically during developmenteslint
- lintingprettier
- formatterdebug
library.git
. git clone [email protected]:dmartinezgamboa/base-discord-bot-app.git
git remote add {your_name} [email protected]:{your_git_username}/bot
TOKEN="{YOUR_BOT_TOKEN}"
CLIENT_ID="{YOUR_BOT_APPLICATION_ID}"
Create
.env
file in the root directory and paste variables
use
.envSample
as an example
npm install
npm start [--register]
--register
: Registers currently implemented slash commands with Discords API globally. See Registering Commands for more options.
Registering is only necessary for the first time or when command data has been updated.
npm install -D
npm run prepare
npm run dev
Options:
--debug
Adds logging to stdout
. For more options see Debug Logs
src/commands
directory, named {myCommandName}.js
const { SlashCommandBuilder } = require('discord.js')
const myCommand = {
data: new SlashCommandBuilder()
.setName('myName')
.setDescription('my description'),
execute: execute
}
const execute(interaction) => { ... }
module.exports = { myCommand }
src/commands/index.js
.const { myCommand } = require(./commands.js')'
module.exports = [myCommand, ...]
Done! The bot will set this command on the client during initialization.
Reference: https://discordjs.guide/creating-your-bot/command-handling.html#loading-command-files
For any npm
command: (start
, run dev
etc):
npm start [{--register | --register-only} [--guild-id=<guild_id>] [--clear]]
--register
: If only option, registers the currently implemented commands globally with Discord API.--register-only
: Same operation as --register
except the application will exist once registration is complete.--guild-id
: If provided along with a --register*
option, it will register the currently implemented commands only for that specific guild.--clear
: If provided with a --register*
option, will remove any registered commands for that scope (Will be global or guild specific depending on additional options.)Global commands and guild commands are separate lists.
Registering a command globally and for a guild will result in duplicated commands in the server.
Removing a command globally does not remove it from guild lists and vice versa.
Only necessary to run when updating commands. There is a daily limit on registering new commands.
Reference: https://discordjs.guide/creating-your-bot/command-deployment.html#command-registration
Using npm run dev
automatically sets the DEBUG
environment variable, which adds additional logging while the application is running.
For more information on scope, see the
debug
library documentation: https://www.npmjs.com/package/debug#usage