Add user_ids fields for query_members
This commit is contained in:
		| @@ -535,12 +535,11 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): | |||||||
|         } |         } | ||||||
|         await self.send_as_json(payload) |         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 = { |         payload = { | ||||||
|             'op': self.REQUEST_MEMBERS, |             'op': self.REQUEST_MEMBERS, | ||||||
|             'd': { |             'd': { | ||||||
|                 'guild_id': guild_id, |                 'guild_id': guild_id, | ||||||
|                 'query': query, |  | ||||||
|                 'limit': limit |                 'limit': limit | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
| @@ -548,6 +547,13 @@ class DiscordWebSocket(websockets.client.WebSocketClientProtocol): | |||||||
|         if nonce: |         if nonce: | ||||||
|             payload['d']['nonce'] = 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) |         await self.send_as_json(payload) | ||||||
|  |  | ||||||
|     async def voice_state(self, guild_id, channel_id, self_mute=False, self_deaf=False): |     async def voice_state(self, guild_id, channel_id, self_mute=False, self_deaf=False): | ||||||
|   | |||||||
| @@ -1881,7 +1881,7 @@ class Guild(Hashable): | |||||||
|  |  | ||||||
|         return Widget(state=self._state, data=data) |         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| |         """|coro| | ||||||
|  |  | ||||||
|         Request members that belong to this guild whose username starts with |         Request members that belong to this guild whose username starts with | ||||||
| @@ -1907,6 +1907,11 @@ class Guild(Hashable): | |||||||
|         cache: :class:`bool` |         cache: :class:`bool` | ||||||
|             Whether to cache the members internally. This makes operations |             Whether to cache the members internally. This makes operations | ||||||
|             such as :meth:`get_member` work for those that matched. |             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 |         Raises | ||||||
|         ------- |         ------- | ||||||
| @@ -1918,5 +1923,11 @@ class Guild(Hashable): | |||||||
|         List[:class:`Member`] |         List[:class:`Member`] | ||||||
|             The list of members that have matched the query. |             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 |         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) | ||||||
|   | |||||||
| @@ -326,7 +326,7 @@ class ConnectionState: | |||||||
|             else: |             else: | ||||||
|                 log.info('Finished requesting guild member chunks for %d guilds.', len(guilds)) |                 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 |         guild_id = guild.id | ||||||
|         ws = self._get_websocket(guild_id) |         ws = self._get_websocket(guild_id) | ||||||
|         if ws is None: |         if ws is None: | ||||||
| @@ -341,7 +341,7 @@ class ConnectionState: | |||||||
|         future = self.receive_member_query(guild_id, nonce) |         future = self.receive_member_query(guild_id, nonce) | ||||||
|         try: |         try: | ||||||
|             # start the query operation |             # 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) |             members = await asyncio.wait_for(future, timeout=5.0) | ||||||
|  |  | ||||||
|             if cache: |             if cache: | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user