🤖 Telegram Group Cleaner Bot – The Ultimate Defense Against Spam & Bad Content
Welcome to the official guide on building a powerful Telegram group management bot that automatically detects, warns, and removes users who post unwanted content like adult material, referral links, scams, and bad words – in multiple languages! 🚫💥
📌 Overview
The Remove Unwanted Bot is an intelligent, automated Telegram bot created using Python and the python-telegram-bot library. It monitors all messages in a group, detects unwanted or harmful content, issues warnings, and automatically bans repeat offenders after a configurable number of warnings (default is 10).
🔐 Features At a Glance
- 🚫 Deletes messages with offensive language, referral links, crypto spam, and adult content
- ⚠️ Issues warnings (up to 10) to violators with auto-deletion of alert messages
- 🚷 Auto-kicks users who repeatedly break rules
- 📌 Posts stylish, auto-deleting group rules every 10 messages
- 📛 Multi-language bad word detection (English + Tamil, Telugu, Hindi, Kannada, Malayalam, more!)
- 💬 Skips moderation for group admins and owner
- 🎛 Easy customization of bad word lists and link patterns
🚦 How Does It Work?
The bot relies on message handlers to intercept every message in a Telegram group. It uses regular expressions and substring checks to detect bad words and prohibited link patterns. Here's the core workflow:
| Step | Action |
|---|---|
| 1 | User sends a message in the group |
| 2 | Bot checks if sender is admin/owner |
| 3 | If not, the message is scanned for bad content |
| 4 | If bad content found → delete message, issue warning |
| 5 | If warnings reach 10 → kick user permanently |
💻 Code Logic Breakdown
Let’s explore the essential code sections in this bot:
🔧 Bot Setup and Configuration
- BOT_TOKEN: Your Telegram bot token
- BAD_WORDS: List of forbidden terms
- UNWANTED_LINK_PATTERNS: Regex patterns to match spam links
- WARNING_LIMIT: Number of allowed violations before ban (default: 10)
⚙️ Main Functions
handle_messages()– detects and deletes harmful contentstart()– sends group rules and registers grouppopulate_admins_and_owner_for_chat()– fetches admin IDs for permission checks
🧠 Intelligent Message Monitoring
The bot intelligently listens to all text messages in the group and filters them through two key lenses:
- 🚫 Bad words list — checked using substring matching
- 🔗 Unwanted link patterns — filtered using Regular Expressions (regex)
These checks are handled inside the core function handle_messages(), which performs message deletion, warning tracking, and auto-kick if violations reach the limit.
🔍 Real-time Admin Detection
To avoid accidentally punishing trusted users, the bot uses:
await is_admin_or_owner(update, context)
This function checks if a user is a group owner or admin. If they are, the message is ignored completely.
🌍 Multilingual Content Filtering
One of the most powerful parts of this bot is its built-in ability to detect bad words across many Indian languages including:
- 🇮🇳 Tamil (e.g. "புண்டை", "ஓக்க")
- 🇮🇳 Telugu (e.g. "ఒక్క", "పుంతై")
- 🇮🇳 Malayalam (e.g. "പൂണ്ടൈ", "ഒക്ക")
- 🇮🇳 Kannada (e.g. "ಒಕ್ಕ", "ಪೂಲು")
- 🇮🇳 Hindi & Marathi (e.g. "पुंडा", "सुत्ताडी")
These are stored in the BAD_WORDS list. You can freely extend this list to include other slang or harmful words specific to your group or region.
📜 Auto-Posting Group Rules
Every 10 messages, the bot automatically posts the group rules using this logic:
if message_counter % 10 == 0:
rules_message = await update.effective_chat.send_message(GROUP_RULES)
asyncio.create_task(delete_message_after_delay(rules_message, 10))
The rules are customizable and disappear after 10 seconds — keeping the chat clean while still informing members.
📋 Sample Group Rules Content
✨ ⚠️GROUP RULE⚠️ ✨ 🚫 Do not share personal info. 🔞 No adult or 18+ content. 🔗 No referral, crypto, or job links. 📚 Use this group for learning only. 🚨 Violators will be removed.
You can modify the GROUP_RULES string to suit your audience — including emojis, line breaks, and warnings.
❌ Warning System & Auto-Ban
The bot tracks each user’s violations using an in-memory dictionary:
user_warnings = {} # {user_id: warning_count}
Once a user crosses the WARNING_LIMIT (default: 10), they are permanently banned from the group.
💬 Sample Warning Message
⚠️ @username, your message was deleted. Warnings: 3/10. Repeated violations will lead to removal.
This message is deleted after 10 seconds to avoid clutter. You can adjust the deletion delay as needed.
🛠 Bot Configuration Tips
- 🔑 Always keep your bot token private (avoid uploading in public repos)
- 💾 You can store user warnings in a lightweight database like SQLite or Redis
- 🚀 Use
application.run_polling()to auto-restart the bot on crash
🚀 Deployment Guide
Now that your bot is fully functional, let’s explore how to host it so it runs 24/7. Here are three beginner-friendly options:
🔹 1. Heroku (Free Hosting)
- Create a free Heroku account
- Install
Heroku CLIand push your bot code to a new app - Set your BOT_TOKEN as a config variable
🔹 2. VPS (Advanced)
- Choose a provider like DigitalOcean or Linode
- Set up Python and run your bot via a
systemdortmuxsession
🔹 3. PythonAnywhere (Free for small bots)
- Create an account at pythonanywhere.com
- Upload your code and run it via console
🧩 Custom Feature Ideas
Want to go beyond? Here are exciting ways to expand your bot:
- 📊 Dashboard UI – View warning stats and group activity
- 🔘 Inline buttons – Let admins toggle settings (e.g., enable/disable link filters)
- 🌐 Multilanguage rules – Auto-post group rules in user’s language
- 👥 Whitelist users – Allow specific users to bypass filters
🧑🎨 UI/UX Enhancements
While Telegram bots are mostly text-driven, you can make the experience more enjoyable by:
- 🌈 Using emoji + colored rules
- ⏳ Auto-deleting messages after delay
- 📎 Pinned welcome messages with rules
- 🎨 Regular posts with colorful banners
📌 Conclusion
By using this bot, you take a huge step toward making your Telegram group safe, clean, and user-friendly. The bot operates silently yet effectively, balancing automation with flexibility. Whether you manage a student forum, crypto group, or fan club this bot will serve as your trusted digital moderator. 🤖💪
This Content Sponsored by Buymote Shopping app
BuyMote E-Shopping Application is One of the Online Shopping App
Now Available on Play Store & App Store (Buymote E-Shopping)
Click Below Link and Install Application: https://buymote.shop/links/0f5993744a9213079a6b53e8
Sponsor Content: #buymote #buymoteeshopping #buymoteonline #buymoteshopping #buymoteapplication
