A Discord bot that automatically detects and moderates cyberbullying messages in real-time using Machine Learning (SVM classifier with TF-IDF vectorization) and a curated suspicious words list.
- Real-time message analysis — Every message is scanned for cyberbullying content
- Dual detection system — Combines a suspicious words list with a trained SVM model for accurate detection
- Auto-moderation — Deletes offensive messages automatically
- User tracking — Tracks offenders using SQLite, flags users after 10+ violations, and auto-kicks after 20+
- Logging channel — Dedicated channel for admins to see all violations with detailed embeds
- Offense history — Full history of each user's violations stored in database
- Comprehensive admin commands — Check users, view history, reset data, list flagged users, and more
- A message is sent in the server
- The bot preprocesses the text (removes URLs, mentions, normalizes whitespace)
- Checks the message against a list of known suspicious/offensive words
- If no match, the message is vectorized using TF-IDF and classified by the SVM model
- If cyberbullying is detected:
- The message is deleted
- The user is warned
- The incident is logged to the database and log channel
- The user's offense count is incremented
- After exceeding thresholds, users are flagged (10+) or kicked (20+) automatically
├── bot.py # Main bot script
├── bot.log # Bot activity log (auto-generated)
├── discord_bully.db # SQLite database (auto-generated)
├── server_config.json # Server configurations (auto-generated)
├── data/
│ ├── cyberbullying.csv # Training dataset
│ ├── CyberTrollIEEE.csv # Training dataset (IEEE)
│ └── sus_words.csv # Curated list of suspicious/offensive words
├── ipynb/
│ └── main.ipynb # Jupyter notebook for model training & analysis
├── models/ # Pre-trained models (not included in repo)
│ ├── svc_model.pkl # Trained SVM classifier
│ └── tfidf_vectorizer.pkl # Fitted TF-IDF vectorizer
├── requirements.txt # Python dependencies
├── .env # Environment variables (not included in repo)
└── LICENSE
git clone https://github.com/<your-username>/<repo-name>.git
cd <repo-name>The models/ folder is not included in this repository. Download it from Google Drive:
Place the downloaded files (svc_model.pkl and tfidf_vectorizer.pkl) inside a models/ directory at the project root.
pip install -r requirements.txtCreate a .env file in the project root:
DISCORD_BOT_TOKEN=your_discord_bot_token_herepython bot.py- Python 3.8+
- A Discord Bot Token (from the Discord Developer Portal)
- CUDA-compatible GPU (optional, for model training)
All moderation commands require Administrator permission.
| Command | Description |
|---|---|
!help_mod |
Show all moderation commands |
!check_user <username> |
Check a user's offense record |
!user_history <username> [limit] |
View a user's recent offenses (default: 5) |
!reset_user <username> |
Reset a user's offense data |
!flagged_users |
List all flagged users |
!top_offenders [limit] |
Show top offenders (default: 10) |
!set_log_channel [#channel] |
Set the logging channel for violations |
!bot_stats |
Show bot statistics |
Set up a dedicated logging channel to receive detailed reports of all detected violations:
- Create a private channel for moderators (e.g.,
#mod-logs) - Run
!set_log_channel #mod-logsin that channel - The bot will now send detailed embeds for every:
- Cyberbullying detection (with message content, detection method, user info)
- User kick
- User reset
The following values can be adjusted in bot.py:
FLAG_THRESHOLD = 10 # Offenses before user is flagged
KICK_THRESHOLD = 20 # Offenses before user is auto-kicked| Column | Type | Description |
|---|---|---|
| username | TEXT | Primary key, Discord username |
| user_id | INTEGER | Discord user ID |
| count | INTEGER | Total offense count |
| flag | INTEGER | 1 if flagged, 0 otherwise |
| kicked | INTEGER | 1 if kicked, 0 otherwise |
| last_offense | TEXT | ISO timestamp of last offense |
| Column | Type | Description |
|---|---|---|
| id | INTEGER | Auto-increment primary key |
| user_id | INTEGER | Discord user ID |
| username | TEXT | Discord username |
| guild_id | INTEGER | Server ID |
| channel_id | INTEGER | Channel ID |
| message_content | TEXT | The offensive message (truncated to 500 chars) |
| detection_method | TEXT | "word_list" or "ml_model" |
| timestamp | TEXT | ISO timestamp |
The model was trained on the following datasets:
- CyberTrollIEEE.csv — IEEE cybertroll dataset with
contentandannotationcolumns (1 = cyberbullying, 0 = safe) - cyberbullying.csv — Additional cyberbullying dataset
- Discord API — discord.py
- ML Model — SVM (Support Vector Machine) via scikit-learn
- Feature Extraction — TF-IDF Vectorizer
- Database — SQLite
- Training — PyTorch, Transformers, CUDA (GPU-accelerated)
This project is licensed under the MIT License. See the LICENSE file for details.