About this Bot
Sentinel Discord Moderation Bot
A moderation bot built for Discord communities using Python and discord.py. It handles day-to-day moderation tasks, catches spam and invite links automatically, logs server events, and saves warning histories using a local SQLite database.
---
Overview
Sentinel was built to give server administrators a dependable, self-hosted moderation tool that does not depend on third-party cloud dashboards or paid subscriptions. Everything runs directly on your server or machine, storing infraction history and configuration locally in an SQLite database.
The bot supports both Discord slash commands (/) and classic prefix commands (!), handles role hierarchy checks to avoid moderation accidents, and sends DM notifications to users when they are warned, kicked, banned, or timed out.
---
Features
- Moderation toolkit: Commands for kicks, bans, unbans, timeouts, warnings, message purges, slowmode adjustments, channel locks, and role assignment.
- Role hierarchy safety: Moderators cannot ban, kick, or mute members with equal or higher roles, and cannot action server owners or the bot itself.
- Auto-moderation:
@everyone / @here pings.
- Event and audit logging: Sends detailed embeds to a designated log channel whenever messages are edited or deleted, members join or leave, or bans are issued.
- Local database: Uses SQLite through
aiosqlitewith Write-Ahead Logging (WAL) enabled, keeping records of every warning and infraction without requiring an external database server. - Container support: Includes a Dockerfile and docker-compose.yml with persistent data volumes for quick deployment.
Getting Started
Prerequisites
- Python 3.10, 3.11, or 3.12 (if running locally)
- A Discord account and a server where you have administrative privileges
- Docker and Docker Compose (optional, for containerized deployments)
Step 1: Create Your Bot on the Discord Developer Portal
1. Visit the Discord Developer Portal and sign in.
2. Click New Application in the top right. Give your application a name (for example, Sentinel) and accept the terms.
3. Open the Bot section from the left sidebar:
- Click Add Bot (if not already created).
- Under Icon, upload assets/icon.svg (or export it to PNG if you prefer).
- Click Reset Token, copy the generated token, and keep it safe. You will need this for your .env file.
4. Scroll down to Privileged Gateway Intents and enable all three:
- Presence Intent
- Server Members Intent
- Message Content Intent (required for auto-mod and event logging to read message text)
5. Save your changes.
---
Step 2: Invite the Bot to Your Server
1. Open the OAuth2 tab in the sidebar, then select URL Generator.
2. Under Scopes, select:
- bot
- applications.commands
3. Under Bot Permissions, select the permissions Sentinel needs:
- Moderate Members (Timeouts)
- Kick Members
- Ban Members
- Manage Messages (Purge, delete)
- Manage Roles (Role command)
- Manage Channels (Channel lock/unlock)
- View Audit Log
- Send Messages & Embed Links
- Read Message History
4. Copy the generated invite link at the bottom, paste it into your browser, and authorize the bot into your server.
5. In your Discord server settings under Roles, ensure the bot's role is dragged above the roles of members it is expected to moderate. Discord's permission system prevents bots from moderating members whose highest role is equal to or higher than the bot's role.
---
Step 3: Run the Bot
#### Option A: Running Locally
1. Open your terminal and change into the project folder:
cd discord-mod-bot
2. Create and activate a Python virtual environment:
- On Windows (PowerShell):
python -m venv .venv
.\.venv\Scripts\Activate.ps1- On Linux/macOS:
python3 -m venv .venv
source .venv/bin/activate
3. Install the required Python packages:
pip install -r requirements.txt
4. Create your .env configuration file from the template:
- On Windows:
Copy-Item .env.example .env- On Linux/macOS:
cp .env.example .env
5. Open .env in any text editor and fill in your bot token:
DISCORD_TOKEN=your_copied_bot_token_here
CLIENT_ID=your_client_id_here
DEFAULT_PREFIX=!If you want slash commands to register instantly in your testing server rather than waiting for Discord's global cache update, set
GUILD_ID to your server's numerical ID.
6. Start the bot:
python bot.py
---
#### Option B: Running with Docker
If you prefer running Sentinel as a background service with Docker:
1. Copy .env.example to .env and fill in your DISCORD_TOKEN.
2. Build and launch the container in detached mode:
docker compose up -d --build3. Check the logs:
docker compose logs -f4. The SQLite database is automatically persisted to
./data on your host machine, so your configuration and infraction logs will remain safe across container restarts and updates.
---
Configuration
Settings are saved in .env for initial startup and inside the SQLite database for runtime server-specific settings.
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
| DISCORD_TOKEN | Yes | - | The secret bot token from Discord Developer Portal. |
| CLIENT_ID | No | - | Your Discord application client ID. |
| GUILD_ID | No | - | Server ID for immediate guild-scoped slash command synchronization. |
| DEFAULT_PREFIX | No | ! | Fallback prefix for message commands. |
| DATABASE_PATH | No | bot_database.db | Path to the SQLite database file. |
| LOG_LEVEL | No | INFO | Console logging verbosity (DEBUG, INFO, WARNING, ERROR). |
---
Command Reference
Sentinel provides both slash commands and prefix commands. Slash commands are recommended as they include built-in autocompletion and parameter validation.
Moderation Commands
| Command | Arguments | Required Permission | Description |
|---|---|---|---|
| /kick | target, [reason] | Kick Members | Removes a member from the server. Sends a DM notice first. |
| /ban | target, [delete_days], [reason] | Ban Members | Permanently bans a member and optionally purges their recent messages (0 to 7 days). |
| /unban | user_id, [reason] | Ban Members | Unbans a user by their numerical ID. |
| /timeout | target, minutes, [reason] | Moderate Members | Applies a Discord timeout to a member for up to 28 days. |
| /untimeout | target, [reason] | Moderate Members | Removes an active timeout from a member early. |
| /warn | target, reason | Moderate Members | Issues an official warning, DMs the user, and records the infraction in the database. |
| /warnings | target | Moderate Members | Displays all historical warnings and cases recorded for a member. |
| /clearwarn | case_id | Moderate Members | Removes a specific warning case from a user's record. |
| /purge | amount, [member] | Manage Messages | Deletes up to 100 messages at once. Can optionally filter to messages sent by a specific user. |
| /slowmode | seconds, [channel] | Manage Channels | Sets the channel chat delay (0 to 21600 seconds). Set to 0 to turn off slowmode. |
| /lock | [channel], [reason] | Manage Channels | Locks down a channel by disabling Send Messages for @everyone. |
| /unlock | [channel] | Manage Channels | Reopens a previously locked channel for @everyone. |
| /role | action, target, role | Manage Roles | Safely adds or removes a role from a member, checking role hierarchy. |
---
Utility and Server Info Commands
| Command | Arguments | Description |
|---|---|---|
| /userinfo | [target] | Shows an overview of a user: join date, account age, roles, permissions, and warning count. |
| /serverinfo | - | Displays server metrics: member counts, channel distribution, boost tier, and verification level. |
| /botinfo | - | Displays bot uptime, system memory usage, discord.py version, and connected server count. |
| /ping | - | Measures Discord gateway latency, HTTP API response time, and database query latency. |
---
Server Configuration Commands
| Command | Arguments | Required Permission | Description |
|---|---|---|---|
| /setlogchannel | [channel] | Administrator | Sets the channel where mod-logs and audit events are posted. Leave empty to disable. |
| /automod status | - | Administrator | Displays the current AutoMod settings and active filter status. |
| /automod toggle | feature, enabled | Administrator | Toggles individual AutoMod features (anti_spam, anti_invite, bad_words, mass_mentions). |
| /automod addword | word | Administrator | Adds a custom blacklisted word or phrase to the guild's filter. |
| /automod removeword | word | Administrator | Removes a word from the guild's filter list. |
---
Auto-Moderation Details
The auto-moderation module runs on incoming messages before they are processed by regular commands. Server administrators and users with exempt roles are automatically bypassed.
1. Anti-spam:
Tracks message velocity using a sliding time window. If a user posts 5 or more messages within 4 seconds, the bot deletes the offending messages, places the user on a 5-minute timeout, logs an infraction in the database, and alerts the mod-log channel.
2. Anti-invite:
Scans messages using regular expressions for Discord invite URLs (discord.gg/, discord.com/invite/). Unauthorized invites are removed instantly, the user is warned, and an audit entry is created.
3. Bad words filter:
Checks message content against both a built-in list of terms and your server's custom additions (/automod addword). Common leetspeak substitutions are normalized before matching.
4. Mass mention protection:
Catches messages containing more than 5 mentions or unauthorized @everyone / @here attempts. Offending messages are purged and the sender receives a 10-minute timeout.
---
Audit Logging
When you configure a log channel via /setlogchannel #mod-logs, Sentinel automatically posts formatted embed updates for:
- Deleted messages: Records the original author, the channel, and the message text before deletion.
- Edited messages: Shows the previous content alongside the updated text, including a jump link to the message.
- Member joins: Displays user tag, numerical ID, account age, and flags suspicious new accounts.
- Member leaves: Displays member name and how long they were part of the server.
- Member bans and unbans: Cross-references Discord audit logs to identify which moderator performed the action and logs the stated reason.
Project Structure
discord-mod-bot/
├── assets/
│ └── icon.svg # Minimalist cat and shield vector icon
├── cogs/
│ ├── automod.py # AutoMod rules, listeners, and management commands
│ ├── logging.py # Audit log listeners for edits, deletes, joins, and bans
│ ├── moderation.py # Core moderation slash and prefix commands
│ └── utility.py # Userinfo, serverinfo, botinfo, and setup commands
├── database/
│ ├── __init__.py # Database package exports
│ └── db.py # Asynchronous SQLite database manager (aiosqlite)
├── .env.example # Template for environment variables
├── .gitignore # Standard ignores for Python, SQLite, and IDE caches
├── bot.py # Main bot class, cog loader, and error handlers
├── config.py # Environment configuration loader and palette colors
├── Dockerfile # Container build file
├── docker-compose.yml # Docker Compose setup with data persistence
├── LICENSE # MIT License
└── requirements.txt # Python dependencies
---
Frequently Asked Questions
Why are slash commands not showing up in my server?
When commands are registered globally, Discord can take up to an hour to cache them across all servers. For immediate availability during setup and testing, set theGUILD_ID variable in your .env file to your server ID. Guild-level commands register instantly upon bot startup.
Why does the bot say "Missing Permissions" when trying to moderate someone?
In Discord's permission system, a bot cannot moderate any user whose highest role is above or equal to the bot's own highest role. Go to your server settings, select Roles, and move Sentinel's role higher in the list than the roles of regular members. Note that Discord never allows bots to moderate the server owner, regardless of permissions.Why are deleted or edited messages not showing up in the log channel?
1. Ensure you have run/setlogchannel and selected a valid text channel.
2. Verify that the bot has Send Messages and Embed Links permissions in that channel.
3. Make sure the Message Content Intent is turned on in the Discord Developer Portal under the Bot tab.
Where is data stored?
All settings, warnings, and infractions are stored in a local SQLite file namedbot_database.db located in the project root (or inside the /app/data volume if running via Docker). Backing up this single file backs up your entire bot state.
---
License
This project is licensed under the MIT License. See the LICENSE file for details.
Package Versions (2)
Changelog
New Features Added in Version 1.1.0
1. Private Staff Notes (/note)
- /note add <target> <note>: Add internal staff notes on suspicious users without issuing public warnings or alerting the user.
- /note list <target>: View all private notes logged by staff for a member.
- /note remove <note_id>: Delete an obsolete staff note by ID.
2. Emergency Server Raid Defense (/raidmode)
- /raidmode <enabled>: Panic lockdown switch for server administrators. When active, incoming accounts during an organized raid are automatically quarantined with a 24-hour timeout and flagged in the audit log.
3. Auto-Role on Join (/autorole)
- /autorole <role>: Automatically assigns a designated member role to newcomers upon joining (supports disabling or reassigning at any time).
4. Anti-Ghostping Shield
- Added automatic detection in audit logging. If a user tags members in a message and deletes it quickly, Sentinel logs the sender, the mentioned targets, and the deleted text directly to the staff mod-log channel.
5. Channel Sticky Messages (/stickymessage)
- /stickymessage set <content>: Pins a persistent notice or rules card to the bottom of busy channels that automatically re-posts whenever new chat messages are sent.
- /stickymessage remove: Safely removes the sticky message from the channel.
6. Infraction Case Lookup (/case)
- /case <case_id>: Quickly retrieve full case history (punitive action, target, moderator, reason, and exact timestamp).
7. Moderator Activity & Leaderboards (/modstats)
- /modstats [moderator]: View a breakdown of actions taken by a specific moderator, or display the top 10 most active staff leaderboard.
No changelog provided.