skip to Main Content

I want to get a channel’s members’ count but I don’t know which method should I use?

I am not admin in that channel, I just want to get the count number.

EDIT:I am using main telegram api, not telegram Bot api

3

Answers


  1. You can use getChatMembersCount method.

    Use this method to get the number of members in a chat.

    Login or Signup to reply.
  2. It worked for me 🙂

    from telethon import TelegramClient, sync
    from telethon.tl.functions.channels import GetFullChannelRequest
    
    
    api_id = API ID
    api_hash = 'API HASH'
    
    client = TelegramClient('session_name', api_id, api_hash)
    client.start()
    if (client.is_user_authorized() == False):
        phone_number = 'PHONE NUMBER'
        client.send_code_request(phone_number)
        myself = client.sign_in(phone_number, input('Enter code: '))
    channel = client.get_entity('CHANNEL LINK')
    
    members = client.get_participants(channel)
    print(len(members))
    
    Login or Signup to reply.
  3. It is possible to do it also through GetFullChannelRequest in telethon

    async def main():
        async with client_to_manage as client:
            full_info = await client(GetFullChannelRequest(channel="moscowproc"))
            print(f"count: {full_info.full_chat.participants_count}")
    
    
    if __name__ == '__main__':
        client_to_manage.loop.run_until_complete(main())
    

    or to write it without async/await

    def main():
        with client_to_manage as client:
            full_info = client.loop.run_until_complete(client(GetFullChannelRequest(channel="moscowproc")))
            print(f"count: {full_info.full_chat.participants_count}")
    
    
    if __name__ == '__main__':
        main()
    

    Also as above was said, it is also feasible by bot-api with
    getChatMembersCount method. You can curl it or use python to query needed url

    with python code can look like this one:

    import json
    from urllib.request import urlopen
    
    url ="https://api.telegram.org/bot<your-bot-api-token>/getChatMembersCount?chat_id=@<channel-name>"
    with urlopen(url) as f:
        resp = json.load(f)
    
    print(resp['result'])
    

    where <your-bot-api-token> is token provided by BotFather, and <channel-name> is channel name which amount of subscribers you want to know (of course, everything without "<>")

    to check firstly, simply curl it:

    curl https://api.telegram.org/bot<your-bot-api-token>/getChatMembersCount?chat_id=@<channel-name>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search