A Discord bot that you can use as your own.
Built with a robust structure, seamless error handling, and easy configuration. Configure and edit effortlessly for a personalized experience.
This discord bot was made for an IT School in 2020. It has a lot of features including all the latest features from discord.py.
- Administrative Tools
- Custom prefix per guild
- Invite tracker
- Development & Tools
- ANSI color support
- Custom error handling
- Dynamic structure (Does not require a reboot to apply changes in code & files)
- Database support (SQL)
- Docker support
- Image processing
- Logging
- Multiple configs
- Metrics about usage of the bot
- Powerful, dev & debugging commands
- Utility functions
- Socket communication system
- Views system
- Discord support
- AppCommands (Slash-commands)
- Cogs/GroupCogs
- Commands
- ContextMenus (Right-click commands)
- Custom-Modals (Forms)
- Custom-Views (Buttons, Dropdown, ..)
- Groups
- HybridCommands (Slash-commands + Commands)
- User Interaction
- Custom Help command
- Dynamic Starboard
- Language detector & Translation
- Private vocal channel on demand (cog: privatevocal)
- Reddit posts listener
- And more..
- Python 3 >= 3.8
- pip == latest
- discord.py == stable
- SQL
- MariaDB (or MySQL)
Note
More about requirements in the requirements.txt file.
-
Create an application on Discord Developers
-
Enable the bot status in Discord Developers/applications/{YOUR_APP_ID}/bot
-
Please make sure you have enabled each needed
Privileged Gateway Intentsin Discord Developers/applications/{YOUR_APP_ID}/bot #Privileged Gateway Intents for your application. -
Copy the token bot from Discord Developpers/applications/{YOUR_APP_ID}/bot #Token
Tip
In URL replace {YOUR_APP_ID} with your own app/bot ID.
-
Paste your discord bot token after the
BOT_TOKEN=inside/config/.env. -
Configure the default prefix in the
/config/bot.json.
You can run the bot in two ways:
- With Docker (recommended for production)
- Manual setup (recommended for development)
-
Make sure you have Docker installed on your machine.
-
Run the following command in the root of the project:
docker compose --env-file ./config/.env up --build- Your bot is now running !
A Virtual Environment is recommended.
Install python packages with:
pip install -r requirements.txt-
If you are using a database, fill your database credentials in the
/config/.envfile. -
Inside your SQL database, create the required tables, more about in the SQL tables structure section.
Important
If you are NOT using any/or a compatible database, check the Acknowledgement section.
Run the following command in the root of the project:
python bot.pyIf everything is configured correctly, you should see the bot coming online in your Discord server.
Important
If you have not planned to use a SQL database:
- set the
"use_database"field tofalsein the/config/bot.jsonfile. - in the folder
/cogsyou should remove the following files (which are using the database):birthday.py,croissants.py,invite.py,me.py,metrics.py,starboard.py.
To set up a SQL database such as MariaDB or any other SQL database, and host it on a Raspberry Pi or any other server, you need to follow these steps:
-
Install MariaDB or any other SQL database on the desired server. The installation process may vary depending on the operating system and which SQL database you have selected. You may also want to install a graphical user interface for your database, such as phpMyAdmin, which makes it easier to manage and configure your database.
-
Create a new user with password that the bot is going to use and grant the necessary permissions such as
SELECT,INSERT,UPDATE,DELETE, andSHOW DATABASES. -
If the database is on the same server, no additional configuration is usually required. However, if the database is hosted on a different server, you may need to configure network settings to allow access to the database server. Specifically, you might need to open port 3306, which is the default port for SQL databases, on the server where the database is hosted.
-
Create a new database. Add the tables listed in the SQL tables structure section. You can change the structure of the tables as you wish, but you will need to reconfigure some keys/values of the
/config/cogs.json. -
Fill the database settings for your bot in the
/config/.env.
You can find the SQL structure of the tables in /database/structure.sql.
Note
These tables are required in the database if you have planned to use the bot as if provided
To add a new cog, place the Python file in the /cog folder.
While the bot is running, you can dynamically register the cog using the loadcog command followed by the name of the file without the .py extension. If you make changes to the cog after registering it, simply use rl or rel <cog_name> to reload the cog without restarting the bot.
The following commands provide flexibility and efficiency during the development phase, allowing you to seamlessly update and test your bot without restarting it.
| Command | Alias | Description | Example |
|---|---|---|---|
?loadcog <cog_name> |
Loads a cog from the /cogs directory. | ?loadcog basic |
|
?unloadcog <cog_name> |
Unloads a cog from the /cogs directory. | ?unloadcog basic |
|
?reloadallcogs |
rell |
Reloads all cogs inside the /cogs directory. | ?reloadallcogs |
?reload <cog1> <cog2> ... |
rel |
Reloads specified cogs from the /cogs directory. | ?reload basic birthday |
?reloadlatest <n_cogs> |
rl |
Reloads the n latest edited cogs in the /cogs directory. | ?reloadlatest 3 |
?reloadviews |
rv |
Reloads all registered views in the /views directory. | ?reloadviews |
?reloadconfig |
rc |
Reloads all JSON config files inside the /config folder. | ?reloadconfig |
?synctree <guild_id> |
st |
Syncs applications commands with discord. | ?synctree or ?synctree 123456789012345678 |
Most of the time you will be using, rl for reloading the latest edited cogs and rv for reloading all registered views.
These commands are essential for development, often used to quickly apply and test code changes, making the development process smooth and efficient.
Github setup:
- On Github.com go on your project repository
- Then click on
Settings>Actions>Runners>New self-hosted runner. - Then select the right
runner-imagerelated to your machine and the rightarchitecture. - Then follow the
Downloadand theConfigureinstructions.
Server setup:
- If you want to start the self-runner on boot, you can follow this guide.
Warning
The self-hosted runner should have the following permissions, install apps and start/restart services. (install the service as --user usernameWithPermissions)
Discord bot service: This step is made for linux only.
- Create a service file in
/etc/systemd/system/your-service-name.servicewith the following content:
[Unit]
Description=Discord bot startup service
After=multi-user.target
[Service]
Type=simple
Restart=no
User={usernameWithPermissions}
WorkingDirectory=/home/{username}/actions-runner/_work/Discord-Bot/Discord-Bot
ExecStart=python3 /home/{username}/actions-runner/_work/Discord-Bot/Discord-Bot/bot.py
[Install]
WantedBy=multi-user.targetTip
Replace {username} & {usernameWithPermissions} with your username and Discord-Bot/Discord-Bot with your project name.
- Then enable the service with
systemctl enable your-service-name.service