Search code examples
telegram-bottelethon

How to get more than 1000 Kicked Users with Telethon


I had a Telegram group with 3000 members. I lost 2500 members. I want to get the username of all them. I tried with this code, but the method just fetch 1000 items and no more. How could I fetch the other 1500 users?

import os
from telethon import TelegramClient, events
from telethon.tl.types import ChannelParticipantsKicked

api_id = os.getenv('TELEGRAM_API')
api_hash = os.getenv('TELEGRAM_HASH')
chat = -123456789
client = TelegramClient('session_name', api_id, api_hash)

async def main():
    await client.start()
    async for user in client.iter_participants(chat, filter=ChannelParticipantsKicked):
        # Do something with the data

with client:
    client.loop.run_until_complete(main())

Solution

  • you can not fetch more than 1000 members with iter_participants

    look at this issue on Github