I
I
Ilya2021-08-05 11:32:57
Python
Ilya, 2021-08-05 11:32:57

Why is the code not running correctly?

There is a code:

from telethon import TelegramClient, sync


api_id = 'мой id'
api_hash = 'мой хэш'
username = 'мой номер'

client = TelegramClient(username, api_id, api_hash).start()

channels = {d.entity.username: d.entity
            for d in client.get_dialogs()
            if d.is_channel}

for u in client.get_participants(channels['test'], limit=10):
    print(u.id, u.first_name, u.last_name, u.username)


I have channels and groups. I would like to get all users of a group named test . I looked at the channels list and there were only channels that I subscribed to. The task is to get the users of the group named test, if you are not an administrator.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
I Phoenix I, 2021-08-07
@PhoenixX33i

Maybe you do not see the groups, because you yourself discard them?)
Please pay attention to if d.is_channel

channels = {
            d.entity.username: d.entity
            for d in client.get_dialogs()
                    if d.is_channel
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question