Creating a Discord Bot from scratch can be tedious. We made this template for everyone to easily create and deploy customized discord bots.
- NodeJS, NPM, Git is installed in the system.
- The Developer should know basic Javascript.
- Create a
.env
file containing the following:
# You can retrieve them at https://discord.com/developers/applications, when you create your own bot
TOKEN = INSERT_BOT_TOKEN
CLIENT_ID = INSERT_CLIENT_ID
- Run
npm i
in the terminal. - Then, run
npm start
.
- Go to https://discord.com/developers/applications and create a new Application.
- On the Left Menu Panel, Go to "Bot", and create a new bot.
- Again on the Left Menu Panel, Go to "OAuth2" → "URL Generator"
- Under Scopes, Tick the "bot" checkbox.
- Under Scopes, Tick the "applications.commands" checkbox.
- Under Bot Permissions, Tick the "Adminstrator" checkbox.
- 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.
- Going back to the program files, Create a
.env
file containing the following:
# You can retrieve them at https://discord.com/developers/applications, when you create your own bot
TOKEN = INSERT_BOT_TOKEN
CLIENT_ID = INSERT_CLIENT_ID
- 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/handlers folder (e.g. message-create-handler.js and button-handler.js).
- The
.env
file is not meant to be pushed to the remote repository. We added the file only for faster setup and straight-forward instruction.