-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}")
ggindinson
  • 21
  • 7

1 Answers1

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.

ColinShark
  • 1,047
  • 2
  • 10
  • 18
  • Thank you! Any ideas why it can get for example 5139 users when in fact there are 6178? – ggindinson Dec 16 '21 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 '21 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 – Rohithaditya Mar 09 '22 at 14:51