diff --git a/discord/gateway.py b/discord/gateway.py index 15368d565..2ddd2a236 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 5d212ccc7..ba5132a56 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 758723480..57bd5b3c3 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: