🤖 AI-powered anti-spam bot for Telegram groups
🎯 Demo Bot • 📢 Channel • 💬 Group • 简体中文
If you use this project, please:
- ✅ Keep the developer information in the Bot (
/startcommand) - ✅ Credit the source in your project
- ✅ Do not remove copyright notices from the code
This is the most basic respect for open source authors 🙏
💡 Official Version: This is the official repository maintained by the original author. Forks may be outdated.
- 🛡️ Smart Detection: AI-powered spam detection for text, images, and stickers
- 🎯 Multi-Model Support: Choose from OpenAI, Qwen, or DeepSeek
- 📊 Flexible Strategy: Configurable detection days, message count, verification times
- 🔓 User-Friendly Management: One-click unban, admin panel
- 📢 Ad Buttons: Custom advertisement buttons on ban notifications
- ⚡ High Performance: Async processing, non-blocking
- 🔄 Verification System: Verified users skip future checks, saving API calls
- 🔁 Auto Retry: AI API calls auto-retry on failure (3 times, exponential backoff)
- 📝 Persistent Logs: Runtime logs saved to
data/bot.log - 📈 Statistics:
/statscommand to view detection statistics - 🌍 Multi-Language: Support for Chinese/English
pip install -r requirements.txtcp config.example.yml config.yml
# Edit config.yml with your settingsRequired:
telegram.token- Your bot token (from @BotFather)telegram.owners- Super admin ID (your Telegram ID, get it from @userinfobot)- AI model config (choose one):
openai.api_key- OpenAI API Keyqwen.api_key- Qwen API Keydeepseek.api_key- DeepSeek API Key
python bot.py- Add the bot to your group
- Set as admin (requires delete messages & ban users permissions)
- Send
/startto test
/start- View bot info/admin- View admin panel (admins only)
/unban <user_id>- Unban user/unban(reply to message) - Unban the replied user
/add_ad title|link|expiry|weight- Add ad button/all_ad- View all ads/del_ad <ID>- Delete ad/stats- View runtime statistics (detection count, ban rate, etc.)
Ad Button Example:
/add_ad Official Channel|https://t.me/mychannel|2099-12-31 23:59:59|100
telegram:
token: "your-bot-token"
owners: ["your-telegram-id"] # Super admins
allow_any_group: true # Allow any group
groups: [] # Whitelist groups (when allow_any_group=false)
# Language setting
language: "zh" # Options: zh / enai_model: "deepseek" # Options: openai / qwen / deepseekModel Comparison:
| Model | Advantage | Price | Image Support |
|---|---|---|---|
| OpenAI | High accuracy | Expensive | ✅ gpt-4o-mini |
| Qwen | Good for Chinese | Medium | ✅ qwen-vl-max |
| DeepSeek | Cheap | Lowest | ❌ |
strategy:
joined_days: 3 # Days since joining threshold
min_messages: 3 # Minimum message count
spam_score: 80 # Spam score threshold (0-100)
verification_times: 1 # Verification pass limit
check_message_count: true # Check message countStrategy Explanation:
- joined_days: Users who joined more than N days ago skip detection
- min_messages: Users with more than N messages skip detection (requires
check_message_count: true) - verification_times: Users who passed N verifications skip detection (0=unlimited)
- spam_score: Only ban when AI score exceeds this value
Common Scenarios:
strategy:
joined_days: 999999
verification_times: 0
check_message_count: falsestrategy:
joined_days: 3
min_messages: 3
verification_times: 1
check_message_count: truestrategy:
joined_days: 7
min_messages: 5
verification_times: 2
check_message_count: trueBan notifications display custom buttons:
🚫 Spam Detected
...
⚠️ User has been permanently banned
[🔓 Unban] ← Admins can click
[📢 Official Channel] ← Your ad
[💎 VIP Group] ← Your ad
Manage Ads:
# Add
/add_ad Official Channel|https://t.me/channel|2099-12-31 23:59:59|100
# View
/all_ad
# Delete
/del_ad 1# 1. Edit config
cp config.example.yml config.yml
vim config.yml
# 2. Start
docker compose up -d
# 3. View logs
docker compose logs -fUser sends message
↓
Check if admin → Yes → Allow
↓ No
Check if needs detection → No → Allow
↓ Yes
AI analyzes content
↓
Score < threshold → Allow + verification count +1
↓
Score ≥ threshold → Ban + delete message + send notification
If you have a self-hosted Telegram API server:
export TELEGRAM_API_URL="https://your-api-server.com"
python bot.pyDefault: data/bot.db
Modify:
database:
path: "custom/path/bot.db"- 👨💻 Developer: 狼哥 (@luoyanglang)
- 📦 GitHub: @luoyanglang
- 🌟 Official Project: github.com/luoyanglang/AI-Anti-Spam-Bot
- 📢 Official Channel: @langgefabu
- 💬 Discussion Group: @langgepython
- 🎯 Demo Bot: @xiaolangzaibot - Add to your group to test!
If this project helps you, consider supporting the developer:
- ⭐ Give this project a Star on GitHub
- 📢 Share with others who might need it
- 🐛 Report bugs and suggest features
- ☕ Buy me a coffee
Your support keeps this project alive
Issues and Pull Requests are welcome!
MIT License
Thanks to all contributors and users for your support!
Important Notice:
- This project is open source under the MIT License
- Commercial use is allowed, but please keep the developer information
- If you modify or distribute this project, please credit the original author
- This is respect for open source spirit and motivation for continuous development
⭐ If this project helps you, please give it a Star!
💰 Support the developer to keep this project alive!