You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe the idea is awesome and would benefit the framework
I have searched in the issue tracker for similar requests, including closed ones
Description
Hi,
I'm trying to develop a bot to clean deleted accounts and last seen a long time ago on my channels. Some people with bad intentions added me many fake users and I don't want em on my channels. This is my current code:
from pyrogram import Client
from pyrogram.types import ChatPermissions
from datetime import datetime
import time
# Inserta el chat_id de la conversación de Telegram donde se ejecutará el bot
chat_id =
# Inserta el token de tu bot de Telegram
bot_token = ""
# Inserta tu api_hash y api_id de Pyrogram
api_id = ""
api_hash = ""
async def remove_deleted_accounts(client, chat_id, offset=0, step=200):
total = await client.get_chat_members_count(chat_id)
print("Total members: " + str(total))
itrs = (total//step) + 1
members_list = []
itr = 1
while itr <= itrs:
time.sleep(1)
print("VUELTA")
async for member in client.get_chat_members(chat_id, query=""):
try:
print(str(member.user.id) + ' ' + str(member.user.username) + ' ' + str(member.user.status))
if member.user.is_deleted or str(member.user.status) == "UserStatus.LONG_AGO":
user_id = member.user.id
print(str(datetime.now()) + f" Removing deleted account: {user_id}")
await client.ban_chat_member(chat_id, user_id)
# Espera un breve momento para evitar el exceso de solicitudes
time.sleep(1)
except Exception as e:
print(e)
offset += step
itr += 1
async def main():
async with Client("bot", bot_token=bot_token, api_id=api_id, api_hash=api_hash) as app:
# Llama a la función para remover cuentas eliminadas
await remove_deleted_accounts(app, chat_id)
if __name__ == "__main__":
# Execute the coroutine using asyncio
import asyncio
asyncio.run(main())
However, I can only get 200 members. Is there any wa to filter members that are deleted or last seen a long time ago?
Thanks!
The text was updated successfully, but these errors were encountered:
You can't get more than 200 users in a channel and 10k in a chat - that's a telegram limitation.
The most you can do is to try to get all users by searching through get_chat_members with query parameter.
Checklist
Description
Hi,
I'm trying to develop a bot to clean deleted accounts and last seen a long time ago on my channels. Some people with bad intentions added me many fake users and I don't want em on my channels. This is my current code:
However, I can only get 200 members. Is there any wa to filter members that are deleted or last seen a long time ago?
Thanks!
The text was updated successfully, but these errors were encountered: