Y
Y
yxtiblin2022-04-07 19:32:47
Python
yxtiblin, 2022-04-07 19:32:47

How to get information about users of a TG channel?

I use telethon, at first I tried to use get_participants and inter_participants, but I got errors and then I saw the following code in off documentation and tried it with it

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

offset = 0
limit = 100
all_participants = []

while True:
    participants = client(GetParticipantsRequest(
        channel, ChannelParticipantsSearch(''), offset, limit,
        hash=0
    ))
    if not participants.users:
        break
    all_participants.extend(participants.users)
    offset += len(participants.users)

But I am getting an error
AttributeError: 'coroutine' object has no attribute 'users'

If I delete .users then I get the same error I got when using the get_participants and inter_participants methods. What is the reason for these errors?
TypeError: 'coroutine' object is not iterable

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
i3a4em, 2022-04-07
@yxtiblin

participants in your case is a coroutine. If the result of its execution is needed, then it must be expected. If you've looked at the telethon docs, you should have noticed links to the asyncio docs.
It's done like this. But I wouldn't use asyncio if I were you. Or read the documentation first.
participants = await client...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question