LonamiWebs / Telethon

Pure Python 3 MTProto API Telegram client library, for bots too!

Home Page:https://docs.telethon.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

unable to get all channel participants

SofiaKonetskaya opened this issue · comments

Code that causes the issue

import telethon

client = telethon.TelegramClient('bottest', api_id, api_hash, proxy=proxy
                                 ).start(bot_token=bot_token)
async def channelusers(channel_id):
    participants = client.iter_participants(channel_id)
    participants_ids = []
    async for participant in participants:
        participants_ids.append(participant.id)

Expected behavior

I expect to receive a list with the ids of all channel subscribers

Actual behavior

I get a list of 200 subscribers, although in reality there are more. Moreover, for groups (not channels) this code works correctly.
I also tried to get the list of participants using a While loop (code below), but it did not work - it only finds 202 participants:

while True:
    try:
        participants = client(GetParticipantsRequest(channel_id, ChannelParticipantsSearch(''), offset, limit, hash=0))
        if not participants.users:
            break
        all_participants.extend(participants.users)
        offset += len(participants.users)
        print(len(participants.users))

    except Exception as e:
       print(e)
       sys.exit()

Traceback

No response

Telethon version

1.33.1

Python version

3.7

Operating system (including distribution name and version)

Windows 10

Other details

No response

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

The Telegram API refuses to return all participants, presumably to reduce spam. This is not something a library like Telethon can fix or work around.

Thanks for your reply!
If it's not too much to ask. Could you tell me if it’s possible to use Telethon to delete all subscribers of the channel, which I am the administrator of, except for the specified list of participants.
I wanted to do this using a loop through all the participants, but apparently this is impossible.