Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get channel's members count with telegram api

Tags:

api

telegram

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

like image 276
Leo Avatar asked Aug 27 '17 08:08

Leo


2 Answers

You can use getChatMembersCount method.

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

like image 198
Sean Avatar answered Sep 23 '22 20:09

Sean


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))
like image 29
Wadi Avatar answered Sep 20 '22 20:09

Wadi