Creating a Discord Bot from scratch can be tedious. We made this template for everyone to easily create and deploy customized discord bots.
- JavaScript
- NodeJS and NPM
- Node Packages:
- Create a
.env
file containing the following (use the template provided):
TOKEN = INSERT_BOT_TOKEN
CLIENT_ID = INSERT_CLIENT_ID
- Run
npm i
in the terminal. - Then, run
npm start
. - Go to your Discord Server where you added your bot, and try to run the command
/hello
.
- Go to the Discord Developers Panel and create a new Application.
- After creating your app, on the Left Menu Panel, Go to "Bot", and create a new bot.
- This will give you a new "Token". Copy it and paste it to your
.env
file. Do not share this token to anyone.
- Again on the Left Menu Panel, Go to "OAuth2" → "URL Generator".
- Under Scopes, Tick the
bot
andapplications.commands
checkboxes. - Under Bot Permissions, Tick the
Administrator
checkbox.
- Under Scopes, Tick the
- If you scroll down, you will see a Generated URL section. Copy it and paste it to your web browser's address bar. This will allow you to invite your newly created bot to your own Discord Server.
- Run
npm start
in the terminal. - Go back to your Discord Server where you added your bot, and try to run the command
/hello
.
Each command is a separate .js
file. All of the commands are located in ./src/commands/. You can use the already-included-sample-command file, hello.js, as a guide. To add choices to your slash command, refer to this documentation.
- We highly suggest to not write your program inside index.js but instead create handlers for listeners for better organization. In our convention, we place these events in the ./src/listeners folder and in the ./src/handlers folder.
- The
.env
file and tokens inside it are not meant to be pushed to the remote repository.