Skip to content

About

πŸ€– Discord bot in Python (discord.py) with slash commands: calculator, games, trivia, moderation (ban/unban, clear) and utilities.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Latest commit

Β 

History

5 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

discord-bot

A Discord bot built with discord.py to automate tasks, provide entertainment and help with server moderation. All commands are slash commands (/).

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)

/calc operators

  • 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

Requirements

Discord setup

  1. Create an application in the Developer Portal and add a Bot.
  2. Under Bot β†’ Privileged Gateway Intents, enable Server Members Intent, Presence Intent and Message Content Intent (the bot uses all intents).
  3. Under OAuth2 β†’ URL Generator, select the scopes bot and applications.commands, and the permissions the bot needs (Ban Members, Kick Members, Manage Roles, Manage Messages, Moderate Members, Send Messages, Embed Links).
  4. Open the generated URL to invite the bot to your server.

Installation

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.txt

Create a .env file in the project root (it is git-ignored):

DISCORD_TOKEN=your-bot-token

Run the bot:

python bot.py

On startup the bot syncs its slash commands. It can take a few minutes for new commands to appear in Discord.

Running 24/7 on a Linux server (systemd)

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.target

Then enable and start it:

sudo systemctl daemon-reload
sudo systemctl enable --now discord-bot

Useful 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 pull

Updating

cd ~/discord-bot
git pull
source venv/bin/activate && pip install -r requirements.txt
sudo systemctl restart discord-bot

Project structure

discord-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.

Contributing

Feel free to fork the repository and submit pull requests. Contributions are welcome!

About

πŸ€– Discord bot in Python (discord.py) with slash commands: calculator, games, trivia, moderation (ban/unban, clear) and utilities.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages