0

Using Pyrogram I am trying to get the id of users who are chat members, but the get_chat_members function does not return all users, about 5-10 depending on the selected group, although there are many more in the chat. How do I get all users?

from pyrogram import Client

# Target supergroup
TARGET = "id"

app = Client("my_account", api_id=api_id, api_hash=api_hash)

async def main():
    async with app:
        async for member in app.get_chat_members(TARGET):
            print(member.user.id)


app.run(main())

I tried to use the iter_chat_members method from an older version of pyrogram, but the result is the same

1 Answers1

0

You might need to remove any limit:

async def main():
   async with Client("anon", api_id, api_hash) as app:
        async for member in app.get_chat_members(TARGET, limit=0):
            print(member.user.id)


asyncio.run(main())
0stone0
  • 34,288
  • 4
  • 39
  • 64
  • No, it doesn't work. I tried to use any limits as 0, 50, 200 but it doesn't help – Verese404 Jun 16 '23 at 14:47
  • I've just tested your code an I get all the members ID back as expected; about 72 id's for my chat. – 0stone0 Jun 16 '23 at 14:49
  • I try to get ids from group with 238 members but I get only 3 id. Maybe it is because I'm not administrator of this group? – Verese404 Jun 16 '23 at 15:01
  • I'm also not a admin, there must be something else going on. Not sure what tho, maybe add a sleeper to make sure your not spamming Telegram – 0stone0 Jun 16 '23 at 15:03
  • I have three different groups on my account. For a group with 238 members, I get all their id, for a group with 515 only 3, and for 1849 only 10 – Verese404 Jun 16 '23 at 15:20