[Python] Telegram Bot: Users removed by bot/admin land in "Removed Users" list and can't...

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I'm building a Telegram bot using python-telegram-bot to manage group membership based on subscription status. When a user's subscription expires, the bot removes them from the group using ban_chat_member (optionally followed by unban_chat_member for a "kick" effect).

    Problem: After removal, users appear in the "Removed Users" list in group settings. Telegram shows "Removed by + Name of Admin (Bot)". So in the end the function of a kick is not there and its going for a perma ban. Even after manually unbanning, these users cannot rejoin the group via invite links, and get instant banned again. Sometimes manual removal works, sometimes it doesn't.

    [​IMG]

    async def remove_users_from_group(bot, user_ids):
    for user_id in user_ids:
    try:
    await bot.ban_chat_member(CHANNEL_ID, user_id, until_date=int(datetime.now(timezone.utc).timestamp()) + 30)
    await bot.unban_chat_member(CHANNEL_ID, user_id)
    logging.info(f"User {user_id} temp remove. (Kick).")
    except Exception as e:
    logging.error(f"Error while removing the user. {user_id}: {e}")


    What’s the problem like? Is there a solution?

    Continue reading...

Compartilhe esta Página