skip to Main Content

I want to know if a user with specific id is joined in my telegram channel which I’m admin in it using telethon. I already tried getting list of all users of my channel but it returns at most 200 users. I need to check user by user that if it is joined or not.

2

Answers


  1. You can use GetParticipantRequest to check if the user is in chat. If not, it would return an error: telethon.errors.rpcerrorlist.UserNotParticipantError.

    Login or Signup to reply.
  2. This work for my.

        class GetParticipantsInChannels(object):
            __all_participants:list
            def load_participants_users(self, session, api_id, api_hash, 
                channel_username):
                all_participants=[]
                with TelegramClient( session, api_id, api_hash) as client:
                    channel = client.get_entity(channel_username)
                    offset=0
                    while True:
                        participants = client(
                            GetParticipantsRequest(
                                channel,
                                ChannelParticipantsSearch(''),
                                offset,
                                limit=16000,
                                hash=0
                            )
                        )
                        if not participants.users:
                            break
                        all_participants.extend(participants.users)
                        offset += len(participants.users)
                self.__all_participants=all_participants
    
    participantsChannel = GetParticipantsInChannels()
    participantsChannel.load_participants_users( session, 
                        api_id, api_hash, channel_username)
    usernames = participantsChannel.get_usernames()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search