-1

How can I get all members of chat ids? I tried app.get_chat_members, but i need only user id, and nothing else. Tried this:

    countingusers=app.get_chat_members(f"{link}")

1 Answer 1

0

app.get_chat_members() only returns 200 members at a time. If you want to iterate over all members, you can use app.iter_chat_members() instead. To get just the user_id's, you could use a list comprehension:

counting_users = [x.user.id for x in app.iter_chat_members(chat_id)]

Then your counting_users variable is a list of user_id's.

3
  • Thank you! Any ideas why it can get for example 5139 users when in fact there are 6178?
    – ggindinson
    Dec 16, 2021 at 12:49
  • Likely because the Server simply refuses to return any more. I'm not Telegram, so no idea what actually causes that.
    – ColinShark
    Dec 16, 2021 at 15:44
  • counting_users = [x.user.id for x in bot.iter_chat_members(chati)] TypeError: 'async_generator' object is not iterable i am getting error Mar 9, 2022 at 14:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.