A Discord bot designed to automatically ban users with blacklisted keywords in their username or nickname, and provide a suite of moderation slash commands to manage banned words and user moderation actions easily.
- Automatic banning of users whose username or nickname contains any blacklisted keyword.
- Real-time detection on user join and nickname updates.
- Moderation slash commands for admins:
/addword <word>— Add a word to the banned keywords list./removeword <word>— Remove a word from the banned keywords list./listwords— List all currently banned keywords./clearbannedwords— Clear all banned keywords./banuser <user> [reason]— Ban a specified user with an optional reason./unbanuser <user>— Unban a specified user./kickuser <user> [reason]— Kick a specified user with an optional reason./addlogchannelid <channel>— Add a channel to send ban/kick logs.
- Python 3.8+
discord.pylibrary (Discord API wrapper)python-dotenvfor environment variable management- Discord Slash Commands via
discord.app_commands
- Python 3.8 or higher installed
- Discord bot application created with a bot token (see Discord Developer Portal)
- The bot added to your Discord server with these permissions enabled:
- Read Messages / View Channels
- Send Messages
- Ban Members
- Kick Members
- Manage Messages (optional, if extending functionality)
- Use Slash Commands (applications.commands scope)
- Enable Server Members Intent in Discord Developer Portal (Bot section → Privileged Gateway Intents)
- Clone the repository or download the source code:
git clone https://github.com/yourusername/discord-moderation-bot.git
cd discord-moderation-bot- Create and activate a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Create a
.envfile in the project root directory with the following content:
DISCORD_TOKEN=your_bot_token_here- Replace
LOG_CHANNEL_IDin the code with your mod-log Discord channel ID, or use/addlogchannelidcommand after starting the bot.
Run the bot with:
python bot.pyUpon startup, the bot will sync slash commands with Discord and begin monitoring user joins and nickname updates.
The bot bans any user whose username or nickname contains blacklisted keywords.
This is checked immediately on user join and anytime their nickname changes.
/addword <word>: Add new banned keyword./removeword <word>: Remove banned keyword./listwords: View banned keywords./clearbannedwords: Clear all banned keywords./banuser <user> [reason]: Ban a user manually./unbanuser <user>: Unban a user./kickuser <user> [reason]: Kick a user./addlogchannelid <channel>: Add a channel for ban/kick logs.
Predefined in the banned_keywords list inside the script. Can be modified live via slash commands.
The bot sends ban/kick action logs to the channel ID(s) stored in LOG_CHANNEL_ID. Use /addlogchannelid to add more channels dynamically.
Make sure the bot has the following intents enabled both in the code and on Discord Developer Portal:
- Members intent enabled in code (
intents.members = True) - Server Members Intent enabled in Discord Developer Portal under Bot settings.
Contributions are welcome! Feel free to open issues or pull requests to improve the bot functionality.
This project is licensed under the MIT License.
For support or questions, open an issue or contact the maintainer: @CryptoMax_07
DISCORD_TOKEN=YOUR_DISCORD_BOT_TOKEN/addlogchannelid #mod-log