Search code examples
pythonpyrogram

get all chat members id pyrogram


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}")

Solution

  • 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.