M
M
mrpyus2017-10-03 15:25:30
PHP
mrpyus, 2017-10-03 15:25:30

How to get the number of members of a Telegram channel using the API?

Hello! Please help me find a command on how to get the value of the number of subscribers on the channel I am subscribed to using the Telegram API. Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
pavlyk, 2017-10-11
@pavlyk

It seems to be
https://core.telegram.org/bots/api#getchatmemberscount

D
dydoser, 2017-10-22
@dydoser

goodbye: tgspambot.tk
just be careful, I was banned for using it

E
EXL, 2017-12-10
@EXL

Using Python 3 is very simple:

from time import sleep

from telethon import TelegramClient

from telethon.tl.functions.channels import GetParticipantsRequest
from telethon.tl.types import ChannelParticipantsSearch

api_id = <app_id>
api_hash = '<app_hash>'
phone = '+88005553535'
group_link = 't.me/joinchat/<group_hash>'

client = TelegramClient('session_name', api_id, api_hash)
client.connect()
channel = client.get_entity(group_link)

if not client.is_user_authorized():
    client.send_code_request(phone)
    client.sign_in(phone, input('Please Enter the verification code: '))

def get_users(a_channel):
    offset = 0
    limit = 100
    all_participants = []
    while True:
        participants = client.invoke(GetParticipantsRequest(
            a_channel, ChannelParticipantsSearch(''), offset, limit, hash=0
        ))
        if not participants.users:
            break
        all_participants.extend(participants.users)
        offset += len(participants.users)
        sleep(1)
    return all_participants

def print_users(a_users):
    for user in a_users:
        print(user.username)

print_users(get_users(channel))

Read more:
https://github.com/LonamiWebs/Telethon
https://github.com/LonamiWebs/Telethon/wiki/Retrie...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question