1818
1919import logging
2020import time
21- from typing import Union
21+ from typing import Union , List
2222
2323import pyrogram
2424from pyrogram .api import functions , types
@@ -45,7 +45,7 @@ def get_chat_members(
4545 limit : int = 200 ,
4646 query : str = "" ,
4747 filter : str = Filters .ALL
48- ) -> "pyrogram.ChatMembers" :
48+ ) -> List [ "pyrogram.ChatMember" ] :
4949 """Get a chunk of the members list of a chat.
5050
5151 You can get up to 200 chat members at once.
@@ -59,15 +59,16 @@ def get_chat_members(
5959
6060 offset (``int``, *optional*):
6161 Sequential number of the first member to be returned.
62- Defaults to 0 [1]_.
62+ Only applicable to supergroups and channels. Defaults to 0 [1]_.
6363
6464 limit (``int``, *optional*):
6565 Limits the number of members to be retrieved.
66+ Only applicable to supergroups and channels.
6667 Defaults to 200, which is also the maximum server limit allowed per method call.
6768
6869 query (``str``, *optional*):
6970 Query string to filter members based on their display names and usernames.
70- Defaults to "" (empty string) [2]_.
71+ Only applicable to supergroups and channels. Defaults to "" (empty string) [2]_.
7172
7273 filter (``str``, *optional*):
7374 Filter used to select the kind of members you want to retrieve. Only applicable for supergroups
@@ -78,6 +79,7 @@ def get_chat_members(
7879 *"bots"* - bots only,
7980 *"recent"* - recent members only,
8081 *"administrators"* - chat administrators only.
82+ Only applicable to supergroups and channels.
8183 Defaults to *"all"*.
8284
8385 .. [1] Server limit: on supergroups, you can get up to 10,000 members for a single query and up to 200 members
@@ -86,7 +88,7 @@ def get_chat_members(
8688 .. [2] A query string is applicable only for *"all"*, *"kicked"* and *"restricted"* filters only.
8789
8890 Returns:
89- :obj:`ChatMembers `: On success, an object containing a list of chat members is returned.
91+ List of :obj:`ChatMember `: On success, a list of chat members is returned.
9092
9193 Raises:
9294 RPCError: In case of a Telegram RPC error.
@@ -95,14 +97,16 @@ def get_chat_members(
9597 peer = self .resolve_peer (chat_id )
9698
9799 if isinstance (peer , types .InputPeerChat ):
98- return pyrogram .ChatMembers ._parse (
99- self ,
100- self .send (
101- functions .messages .GetFullChat (
102- chat_id = peer .chat_id
103- )
100+ r = self .send (
101+ functions .messages .GetFullChat (
102+ chat_id = peer .chat_id
104103 )
105104 )
105+
106+ members = r .full_chat .participants .participants
107+ users = {i .id : i for i in r .users }
108+
109+ return pyrogram .List (pyrogram .ChatMember ._parse (self , member , users ) for member in members )
106110 elif isinstance (peer , types .InputPeerChannel ):
107111 filter = filter .lower ()
108112
@@ -123,18 +127,20 @@ def get_chat_members(
123127
124128 while True :
125129 try :
126- return pyrogram .ChatMembers ._parse (
127- self ,
128- self .send (
129- functions .channels .GetParticipants (
130- channel = peer ,
131- filter = filter ,
132- offset = offset ,
133- limit = limit ,
134- hash = 0
135- )
130+ r = self .send (
131+ functions .channels .GetParticipants (
132+ channel = peer ,
133+ filter = filter ,
134+ offset = offset ,
135+ limit = limit ,
136+ hash = 0
136137 )
137138 )
139+
140+ members = r .participants
141+ users = {i .id : i for i in r .users }
142+
143+ return pyrogram .List (pyrogram .ChatMember ._parse (self , member , users ) for member in members )
138144 except FloodWait as e :
139145 log .warning ("Sleeping for {}s" .format (e .x ))
140146 time .sleep (e .x )
0 commit comments