Telethon icon indicating copy to clipboard operation
Telethon copied to clipboard

TelegramClient.iter_participants errors when encounters a ChannelParticipantLeft

Open Manuel1510 opened this issue 2 years ago • 5 comments

Checklist

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

Code that causes the issue

for user in client.iter_participants(some_channel, filter=ChannelParticipantsBanned("")):
    pass

Traceback

    for user in client.iter_participants(some_channel, filter=ChannelParticipantsBanned("")):
  File "/home/manuel/.local/lib/python3.7/site-packages/telethon/requestiter.py", line 74, in __anext__
    if await self._load_next_chunk():
  File "/home/manuel/.local/lib/python3.7/site-packages/telethon/client/chats.py", line 242, in _load_next_chunk
    user_id = participant.user_id
AttributeError: 'ChannelParticipantLeft' object has no attribute 'user_id'

Manuel1510 avatar Dec 03 '21 22:12 Manuel1510

Ah, I have forgotten about this issue. I confirm this bug and will publish a solution soon.

igerzog avatar Dec 16 '21 11:12 igerzog

According to the TDLiib developer these channelParticipantLeft should be ignored: https://t.me/tdlibchat/33266

Manuel1510 avatar Dec 20 '21 15:12 Manuel1510

As a workaround you may change line 236 in chats.py to handle this issue like this:

                if isinstance(participant, (types.ChannelParticipantBanned, types.ChannelParticipantLeft)):

According to documentation ChannelParticipantLeft contains Peer like ChannelParticipantBanned.

igerzog avatar Dec 20 '21 15:12 igerzog

As a workaround you may change line 236 in chats.py to handle this issue like this:

                if isinstance(participant, (types.ChannelParticipantBanned, types.ChannelParticipantLeft)):

According to documentation ChannelParticipantLeft contains Peer like ChannelParticipantBanned.

This would cause the user to be returned though, such users should be skipped as they are not actually banned/restricted

Manuel1510 avatar Dec 20 '21 15:12 Manuel1510

When will this bug be fixed?😑

jack-manual avatar Mar 05 '22 10:03 jack-manual

The bugfix for this will be available in the next version which I plan to release in a few days.

Lonami avatar Sep 20 '22 16:09 Lonami