aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTarek <[email protected]>2020-05-26 11:24:15 +0200
committerRapptz <[email protected]>2020-05-29 23:24:07 -0400
commita972c95f123ece73ee5bcdfb88b43efd98f3e327 (patch)
tree3a5b934d3af0e749d8d2ecaf7b28422a77a7d1e9
parentFix documentation string for guild.premium_subscription_count (diff)
downloaddiscord.py-a972c95f123ece73ee5bcdfb88b43efd98f3e327.tar.xz
discord.py-a972c95f123ece73ee5bcdfb88b43efd98f3e327.zip
Add user_ids fields for query_members
-rw-r--r--discord/gateway.py10
-rw-r--r--discord/guild.py15
-rw-r--r--discord/state.py4
3 files changed, 23 insertions, 6 deletions
diff --git a/discord/gateway.py b/discord/gateway.py
index 15368d56..2ddd2a23 100644
--- a/discord/gateway.py
+++ b/discord/gateway.py
@@ -535,12 +535,11 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
}
await self.send_as_json(payload)
- async def request_chunks(self, guild_id, query, limit, *, nonce=None):
+ async def request_chunks(self, guild_id, query=None, *, limit, user_ids=None, nonce=None):
payload = {
'op': self.REQUEST_MEMBERS,
'd': {
'guild_id': guild_id,
- 'query': query,
'limit': limit
}
}
@@ -548,6 +547,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol):
if nonce:
payload['d']['nonce'] = nonce
+ if user_ids:
+ payload['d']['user_ids'] = user_ids
+
+ if query is not None:
+ payload['d']['query'] = query
+
+
await self.send_as_json(payload)
async def voice_state(self, guild_id, channel_id, self_mute=False, self_deaf=False):
diff --git a/discord/guild.py b/discord/guild.py
index 5d212ccc..ba5132a5 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -1881,7 +1881,7 @@ class Guild(Hashable):
return Widget(state=self._state, data=data)
- async def query_members(self, query, *, limit=5, cache=True):
+ async def query_members(self, query=None, *, limit=5, user_ids=None, cache=True):
"""|coro|
Request members that belong to this guild whose username starts with
@@ -1907,6 +1907,11 @@ class Guild(Hashable):
cache: :class:`bool`
Whether to cache the members internally. This makes operations
such as :meth:`get_member` work for those that matched.
+ user_ids: List[:class:`int`]
+ List of user IDs to search for. If the user ID is not in the guild then it won't be returned.
+
+ .. versionadded:: 1.4
+
Raises
-------
@@ -1918,5 +1923,11 @@ class Guild(Hashable):
List[:class:`Member`]
The list of members that have matched the query.
"""
+ if user_ids is not None and query is not None:
+ raise TypeError('Cannot pass both query and user_ids')
+
+ if user_ids is None and query is None:
+ raise TypeError('Must pass either query or user_ids')
+
limit = limit or 5
- return await self._state.query_members(self, query=query, limit=limit, cache=cache)
+ return await self._state.query_members(self, query=query, limit=limit, user_ids=user_ids, cache=cache)
diff --git a/discord/state.py b/discord/state.py
index 75872348..57bd5b3c 100644
--- a/discord/state.py
+++ b/discord/state.py
@@ -326,7 +326,7 @@ class ConnectionState:
else:
log.info('Finished requesting guild member chunks for %d guilds.', len(guilds))
- async def query_members(self, guild, query, limit, cache):
+ async def query_members(self, guild, query, limit, user_ids, cache):
guild_id = guild.id
ws = self._get_websocket(guild_id)
if ws is None:
@@ -341,7 +341,7 @@ class ConnectionState:
future = self.receive_member_query(guild_id, nonce)
try:
# start the query operation
- await ws.request_chunks(guild_id, query, limit, nonce=nonce)
+ await ws.request_chunks(guild_id, query=query, limit=limit, user_ids=user_ids, nonce=nonce)
members = await asyncio.wait_for(future, timeout=5.0)
if cache: