Discord Test Bot
A Discord test bot used to test out the architecture and implementation of a Discord bot. This project is a way to get familiar with the architecture, APIs and process of maintaining a Discord bot.
Contents
- Contributing
- Install prerequisites
- Running locally
- Running the bot in Discord
- Creating a Discord bot token
- Restricting Bot Access to Channels
- Debugging using VSCode
- Available Commands
- Ask For Help
- Acknowledgements
- Disclaimer
Contributing
So, you want to contribute to this repo? We are glad to recieve PRs from anybody who is interested.
The easiest way to contribute to the development of the bot is using . It starts up an already working version of the bot with all the code so you can start working right now! (You'll have to add the TOKEN
variable in the .env
file)
Follow these steps if you are new to contributing to open source projects:
- Install the required softwares
- Fork the repo
- Clone your forked repo
- Create a new branch on the cloned repo and switch to it
- Make changes to add, update or fix a feature
- Review/test/debug your changes by running the bot locally
- Commit changes and do a Pull Request (aka PR in short)
...and that is it! You are now a contributor! 😎
Install prerequisites
Start by installing the prerequisite software:
Name | Version | Notes |
---|---|---|
Node.js | 12.x |
Download Node.js |
npm (comes bundled with Node) | 6.x |
Does not have LTS releases, we use the version bundled with Node LTS |
git | 2.x |
Download Git |
If you are going to contribute to this project, you will also need a text editor. You can use any text editor you want, but we recommend using VSCode.
If you do not know what these software are, do not worry. These are essential software required to contribute to open source projects.
Running locally
To test and develop this bot you have to run it locally. To run the bot locally, follow these steps:
- Open the folder of your cloned repo
- Create a file in that folder called
.env
and add your Discord bot token like this:
TOKEN=replace-this-with-your-token
- Open the terminal in that folder
- Type the following command and hit enter:
npm i
- Type the following command and hit enter:
npm run dev
- To test the bot in Discord, follow these steps
Running the bot in Discord
This bot requires the Manage Messages
permission to run. So, if you want to use this bot in a Discord server (for testing or production purpose), you will need to grant it the Manage Messages
permission. Luckily we've done
the hard work for you, so that you don't have to do it manually.
First, head over Discord Developer Portal and sign in. After that, select your bot by clicking it's icon.
Just beside your bot's icon, you will see your CLIENT ID
. Copy the CLIENT ID
.
Then replace the YOUR_CLIENT_ID_HERE
with your bot's CLIENT ID
in the link provided below. After that, you can use the link to add the bot to any existing or newly created Discord server (as long as you have the Manage Server
permission).
IMPORTANT NOTE : When you click on the link and want to add the bot to a server, it'll ask for the following permissions. You must approve these permissions for the bot to work correctly:
Manage Roles
, Manage Messages
, Manage Channels
, View Channels
, Read Message History
, Send Messages
This link will automatically create a role specifically for the bot. You need to ensure this role is ABOVE your suspended
role in the server settings or that command will not work properly. Discord only allows a user (or bot) to assign/modify roles placed below their highest role in the list.
Creating a Discord bot token
If you do not have a Discord bot token, you will have to create one. To create a Discord bot token, follow these steps:
- Go to the Developer Portal website and log in
- Click on the "New Application" button
- Enter a name
- Then confirm the pop-up window by clicking the "Create" button. By now you will probably see a page like this:
- Click on the
Bot
tab on the left pane - Click the "Add Bot" button on the right and confirm the pop-up window by clicking "Yes, do it!". After doing so, you'll see a section similar to this one:
- Now pressing the "Copy" button will copy your
Token
to your clipboard.
...and that is all!
Restricting Bot Access to Channels
For testing purposes, you may wish to restrict the bot's access to specific channels.
When you add the bot to your Discord server, the system will automatically create a role for that bot. In order to restrict access to channels, it is important that the bot and bot role do not have the "Administrator" permission (this overrides channel-specific permissions).
For each channel you want keep the bot out of, you need to do the following:
- Select the gear icon next to the channel.
- Select "Permissions".
- Next to the Roles/Members, click the
+
icon. - Add the bot's role.
- The added role should now be selected.
- To the right, go through the permissions list and set each permission to the red "X". The most important permissions to turn off are "Read message history", "Read messages", and "Send messages".
- Save your changes! The Discord application will show a pop-up at the bottom of the screen asking you to "Save Changes" or "Reset" - choose "Save Changes".
Your bot now has no access to that channel, and users cannot send it commands from that channel!
Debugging using VSCode
Provided is an example launch.json
file that should be put into .vscode/launch.json
(this folder and file is untracked by git). This can be used after you start the npm run dev
to help debug the application using breakpoints using
vscode's internal debugger.
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "attach",
"name": "debug",
"restart": true,
"protocol": "inspector",
"port": 9229
}
]
}
Available Commands
Prefix | Description |
---|---|
eightball | Think of your question and get an answer from a magic pool ball! |
help | Get the commands currently available with this bot |
stats | Get current server information! |
coc | Provides the Code of Conduct. |
suspend | Suspends a user for the given reason. This command is only available to admins. Use the format "suspend " |
close | Closes the channel. This command requires admin privileges, and will only work on the automatically created "suspended" channels. Include the user if you want to remove the suspended role. |
forum | Gets the recent forum activity. |
format | Formats the code contained in the message URL. |
trivia | Returns a random bit of trivia! |
quote | Returns a quote from the FCC motivational quotes file |
This bot uses the discord.js library to interact with the Discord API. You can check out the docs for the library here.
Ask For Help
If you have any questions or suggestions about the project, you can create an issue for your question. Please provide as much information as possible when creating an issue. You can also reach us in the FCC's official Discord.
Happy Coding!
Acknowledgements
Disclaimer
This test-bot was created to allow us to test the discord.js library and experiment with setting up our own Discord bot. Our intent is to help FreeCodeCamp set up a bot for their Discord server - however, the files in this repository are NOT associated with FreeCodeCamp in any way.
FreeCodeCamp issue: freeCodeCamp/freeCodeCamp#38711
FreeCodeCamp forum post: https://www.freecodecamp.org/forum/t/create-a-new-camperbot-for-the-official-discord-server/387311