mirror of
https://github.com/TeamPGM/pyrogram.git
synced 2024-11-16 12:51:18 +00:00
Add get_participants example
This commit is contained in:
parent
4561d04c67
commit
8ad2b69bed
38
examples/get_participants.py
Normal file
38
examples/get_participants.py
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
import time
|
||||||
|
|
||||||
|
from pyrogram import Client
|
||||||
|
from pyrogram.api import functions, types
|
||||||
|
from pyrogram.api.errors import FloodWait
|
||||||
|
|
||||||
|
client = Client("example")
|
||||||
|
client.start()
|
||||||
|
|
||||||
|
target = "username" # Target channel/supergroup
|
||||||
|
users = [] # List that will contain all the users of the target chat
|
||||||
|
limit = 200 # Amount of users to retrieve for each API call
|
||||||
|
offset = 0 # Offset starts at 0
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
participants = client.send(
|
||||||
|
functions.channels.GetParticipants(
|
||||||
|
channel=client.resolve_peer(target),
|
||||||
|
filter=types.ChannelParticipantsSearch(""), # Filter by empty string (search for all)
|
||||||
|
offset=offset,
|
||||||
|
limit=limit,
|
||||||
|
hash=0
|
||||||
|
)
|
||||||
|
)
|
||||||
|
except FloodWait as e:
|
||||||
|
# Very large channels will trigger FloodWait.
|
||||||
|
# When happens, wait X seconds before continuing
|
||||||
|
time.sleep(e.x)
|
||||||
|
continue
|
||||||
|
|
||||||
|
if not participants.participants:
|
||||||
|
break # No more participants left
|
||||||
|
|
||||||
|
users.extend(participants.users)
|
||||||
|
offset += limit
|
||||||
|
|
||||||
|
# Now the "users" list contains all the members of the target chat
|
Loading…
Reference in New Issue
Block a user