Search code examples
python-3.xtelegramtelethon

How to get deleted users from channel (telethon)?


In telegram when I click Subscribers it shows me about 50 last users and about 150-200 deleted users.

I tried this:

async for user in client.iter_participants(chat_id):
    if user.deleted:
        print(user)

This gives me only last 50 users and 6-8 deleted users. I need all 150-200 deleted users. How can I get them?


Solution

  • I solved this problem using GetParticipantsRequest with offset parameter somehow like this:

    from telethon.tl.functions.channels import GetParticipantsRequest
    from telethon.tl.types import ChannelParticipantsSearch
    
    chat_id = -123456
    
    offset = 0
    while True:
        participants = await client(GetParticipantsRequest(
            channel=chat_id,
            filter=ChannelParticipantsSearch(''),
            offset=offset,
            limit=10000,
            hash=0
        ))
    
        deleted_users = []
        for user in participants:
            if user.deleted:
                deleted_users.append(user)
    
        if not deleted_users:
            break
    
        # doings with deleted_users