- Preview
- Features
- Getting Started
- Usage
- Project Structure
- Requirements
- Why SQLite?
- Contributing
- License
A modular Discord moderation bot built in Python using discord.py.
It provides a simple warning system, per-server analytics, and a heartbeat task designed to keep track of the bot’s status over time.
The codebase is intentionally small, clean, and easy to extend, ideal for learning or building upon.
Here’s an example of the bot’s embed outputs:
- /warn @user reason
Records a warning for a user in the server’s SQLite database. - /warnings @user
Displays a user’s recent warnings, including moderator, reason, and timestamp.
- /stats
Summarizes moderation activity in the server:- Total warnings
- Unique users warned
- Top warned users
- Warnings per moderator
- Daily warnings (last 7 days)
Runs every 5 minutes, logging:
- Number of servers the bot is in
- Estimated member count
- Total warnings in the database
This provides a simple “health check” for monitoring the bot’s activity.
Language:
- Python 3.10+
Frameworks & Libraries:
- discord.py - Discord API wrapper
- python-dotenv - Environment variable management
- asyncio - Async event loop (standard library)
Database:
- SQLite - Lightweight relational database (built into Python)
Architecture:
- Modular command cogs
- Layered structure (commands, config, database, main runner)
- Slash commands (Discord interactions API)
- Background task (heartbeat loop)
Tooling:
- Git / GitHub for version control
- MIT License
- Preview media included (
/previews/) .env.examplefor environment setup
pip install -r requirements.txtDISCORD_BOT_TOKEN=your_bot_token_here
DISCORD_GUILD_ID=your_test_server_id # optional
python main.pyOnce the bot is running and invited to your server, you can use the following slash commands:
Verifies the bot is online and responding.
Adds a warning to the server’s database.
- The warning includes the user, moderator, reason, timestamp, and guild ID.
- Only users with the “Moderate Members” permission can use this command.
Shows the most recent warnings for a given user in the current server.
- Results display in an embed.
- The response is ephemeral (only visible to you).
Displays moderation analytics for the server:
- Total warnings
- Unique users warned
- Top users by number of warnings
- Warnings per moderator
- Daily warnings (last 7 days)
A background task runs every 5 minutes and logs:
- Number of guilds the bot is in
- Estimated member count
- Total warnings in the database
- A simple uptime-style “heartbeat”
This helps verify that the bot is healthy and operating correctly.
discord-mod-bot/
├─ main.py
├─ config.py
├─ db.py
├─ commands/
│ ├─ basic.py # /ping
│ ├─ moderation.py # /warn, /warnings
│ └─ stats.py # /stats
├─ modbot.sqlite3
└─ requirements.txt
-
main.py
Starts the bot, loads cogs, syncs slash commands, and runs the heartbeat task. -
db.py
Contains all SQLite database logic.
Handles warning creation, lookups, stats aggregation, and over-time analytics. -
commands/
Each file contains a Discord cog with slash commands grouped by purpose.
- Python 3.10 or later
discord.pypython-dotenv- SQLite (built into Python)
For a small to medium-sized Discord bot, SQLite is fast, easy to maintain, and doesn’t require running an external database server. The schema is intentionally simple so it can be swapped for PostgreSQL or MySQL later if needed.
The project is intentionally minimal and easy to expand.
If you'd like to add more commands, analytics, logging, or moderation tools, feel free to open a pull request.
This project is licensed under the MIT License. You’re free to use this project for your own bots or modify it however you like.
