How to Detect and Remove Inactive Users from a Telegram Group Automatically

As your Telegram group grows, inactive members can dilute engagement and clutter conversations. Automating the detection and removal of these members helps maintain a vibrant, active community. Below are two effective methods: using pre-built bots and custom scripts.

Why Clean Up Inactive Members?
  • Improves overall engagement and discussion quality.
  • Prevents spam accounts from accumulating.
  • Provides accurate analytics on active membership.
Method 1: Using a Group Management Bot

Several Telegram bots can automatically track and remove inactive users. Popular choices include Combot, Rose, and Shieldy. Here’s a general setup:

  1. Add the Bot: Invite the bot to your group and grant it administrator privileges.
  2. Configure Inactivity Settings: Use the bot’s dashboard or in-chat commands to set the inactivity period (e.g., 30 days).
  3. Enable Auto-Kick: Turn on the feature to automatically remove members who haven’t sent any messages within the specified period.
Tip: Send a periodic reminder message to warn members before they are removed.
Method 2: Custom Python Script with Telethon

For more control, use a Python script leveraging the Telethon library. The script below checks each member’s last seen timestamp and kicks those inactive beyond a threshold:

from telethon.sync import TelegramClient
from datetime import datetime, timedelta

api_id = YOUR_API_ID
api_hash = 'YOUR_API_HASH'
group = 'your_group_username'
inactivity_days = 30

client = TelegramClient('session', api_id, api_hash)

async def cleanup():
    async with client:
        threshold = datetime.now() - timedelta(days=inactivity_days)
        async for user in client.iter_participants(group):
            if user.status and hasattr(user.status, 'was_online'):
                if user.status.was_online < threshold:
                    try:
                        await client.kick_participant(group, user.id)
                        print(f'Removed {user.id}')
                    except Exception as e:
                        print(f'Failed to remove {user.id}: {e}')

client.loop.run_until_complete(cleanup())
Note: Always backup your session and test in a small group before running on large communities.
Best Practices
  • Warn members at least once before removal with an announcement.
  • Run cleanup during off-peak hours to minimize disruption.
  • Log removed users in a file for reference or appeals.
Conclusion

Automating the removal of inactive users keeps your Telegram group focused and engaged. Whether you choose a pre-built bot for simplicity or a custom script for flexibility, regular cleanup ensures a healthier community environment.

© 2025 Your Company Name. All rights reserved.


0 Comments

Leave a Comment