A Discord bot built with discord.py to automate tasks, provide entertainment and help with server moderation. All commands are slash commands (/).
| Category | Command | Description |
|---|---|---|
| Help | /help [command] |
Lists all commands, or shows details for one |
| Calculator | /calc <op> <a> [b] |
Math operations (see below) |
| Games | /roll |
Rolls a 6-sided die |
/guess |
Guess a number between 1 and 100 (10 tries) | |
/trivia [category] [difficulty] [num_questions] |
Trivia quiz from Open Trivia DB | |
| Moderation | /ban <member> [reason] |
Bans a member |
/unban <user_id> |
Unbans a user by ID | |
/kick <member> [reason] |
Kicks a member | |
/mute <member> [reason] |
Mutes a member (creates a Muted role if needed) |
|
/unmute <member> |
Unmutes a member | |
/clear [amount] |
Deletes up to 100 messages in the channel | |
| Misc | /rep <message> |
Repeats a message |
/botping |
Shows the bot's latency | |
/userinfo |
Shows info about you | |
/activity <text> |
Changes the bot's status (admins only) |
- Two numbers:
+-*/^(power),r(root:r <index> <number>),P(permutations),C(combinations) - One number:
!(factorial),ln,log,sin,cos,tan,exp
Example: /calc arg1:+ arg2:2 arg3:3 β 5
- Python 3.10+
- A Discord bot token (Discord Developer Portal)
- Create an application in the Developer Portal and add a Bot.
- Under Bot β Privileged Gateway Intents, enable Server Members Intent, Presence Intent and Message Content Intent (the bot uses all intents).
- Under OAuth2 β URL Generator, select the scopes
botandapplications.commands, and the permissions the bot needs (Ban Members, Kick Members, Manage Roles, Manage Messages, Moderate Members, Send Messages, Embed Links). - Open the generated URL to invite the bot to your server.
git clone https://github.com/MCCProgrammer/discord-bot.git
cd discord-bot
python3 -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txtCreate a .env file in the project root (it is git-ignored):
DISCORD_TOKEN=your-bot-tokenRun the bot:
python bot.pyOn startup the bot syncs its slash commands. It can take a few minutes for new commands to appear in Discord.
Assuming the project is in /home/<user>/discord-bot with the venv and .env set up as above, create /etc/systemd/system/discord-bot.service:
[Unit]
Description=Discord bot
After=network-online.target
Wants=network-online.target
[Service]
Type=simple
User=<user>
WorkingDirectory=/home/<user>/discord-bot
ExecStart=/home/<user>/discord-bot/venv/bin/python bot.py
Restart=always
RestartSec=5
Environment=PYTHONUNBUFFERED=1
[Install]
WantedBy=multi-user.targetThen enable and start it:
sudo systemctl daemon-reload
sudo systemctl enable --now discord-botUseful commands:
sudo systemctl status discord-bot # check if it's running
journalctl -u discord-bot -f # follow the logs
sudo systemctl restart discord-bot # restart after a git pullcd ~/discord-bot
git pull
source venv/bin/activate && pip install -r requirements.txt
sudo systemctl restart discord-botdiscord-bot/
βββ bot.py # Entry point: sets up the bot and loads every cog in cogs/
βββ cogs/
β βββ calculo.py # /calc
β βββ games.py # /roll, /guess, /trivia
β βββ help.py # /help
β βββ moderation.py # /ban, /unban, /kick, /mute, /unmute
β βββ random_commands.py # /rep, /botping, /activity, /userinfo
β βββ useful.py # /clear
βββ requirements.txt
βββ .env # Your token (not committed)
To add commands, create a new file in cogs/ with a Cog class and an async def setup(bot) function; it is loaded automatically.
Feel free to fork the repository and submit pull requests. Contributions are welcome!