Skip to content

Commit f5683c5

Browse files
NeloBlivionpre-commit-ci[bot]JustaSqu1dDorukyumplun1331
authored
fix: Guild.query_members may accept empty query and limit (#2419)
Signed-off-by: UK <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: JustaSqu1d <[email protected]> Co-authored-by: Dorukyum <[email protected]> Co-authored-by: plun1331 <[email protected]>
1 parent 929e15e commit f5683c5

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ These changes are available on the `master` branch, but have not yet been releas
5353
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
5454
- `Option` may be used instead of `BridgeOption` until 2.7.
5555
([#2417](https://github.com/Pycord-Development/pycord/pull/2417))
56+
- `Guild.query_members` now accepts `limit=None` to retrieve all members.
57+
([#2419](https://github.com/Pycord-Development/pycord/pull/2419))
5658

5759
## [2.5.0] - 2024-03-02
5860

discord/guild.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3361,7 +3361,7 @@ async def query_members(
33613361
self,
33623362
query: str | None = None,
33633363
*,
3364-
limit: int = 5,
3364+
limit: int | None = 5,
33653365
user_ids: list[int] | None = None,
33663366
presences: bool = False,
33673367
cache: bool = True,
@@ -3379,22 +3379,22 @@ async def query_members(
33793379
----------
33803380
query: Optional[:class:`str`]
33813381
The string that the username's start with.
3382-
limit: :class:`int`
3383-
The maximum number of members to send back. This must be
3384-
a number between 5 and 100.
3385-
presences: :class:`bool`
3382+
user_ids: Optional[List[:class:`int`]]
3383+
List of user IDs to search for. If the user ID is not in the guild then it won't be returned.
3384+
3385+
.. versionadded:: 1.4
3386+
limit: Optional[:class:`int`]
3387+
The maximum number of members to send back. If no query is passed, passing ``None`` returns all members.
3388+
If a ``query`` or ``user_ids`` is passed, must be between 1 and 100. Defaults to 5.
3389+
presences: Optional[:class:`bool`]
33863390
Whether to request for presences to be provided. This defaults
33873391
to ``False``.
33883392
33893393
.. versionadded:: 1.6
33903394
33913395
cache: :class:`bool`
33923396
Whether to cache the members internally. This makes operations
3393-
such as :meth:`get_member` work for those that matched.
3394-
user_ids: Optional[List[:class:`int`]]
3395-
List of user IDs to search for. If the user ID is not in the guild then it won't be returned.
3396-
3397-
.. versionadded:: 1.4
3397+
such as :meth:`get_member` work for those that matched. Defaults to ``True``.
33983398
33993399
Returns
34003400
-------
@@ -3414,20 +3414,25 @@ async def query_members(
34143414
if presences and not self._state._intents.presences:
34153415
raise ClientException("Intents.presences must be enabled to use this.")
34163416

3417-
if query is None:
3418-
if query == "":
3419-
raise ValueError("Cannot pass empty query string.")
3417+
if not limit or limit > 100 or limit < 1:
3418+
if query or user_ids:
3419+
raise ValueError(
3420+
"limit must be between 1 and 100 when using query or user_ids"
3421+
)
3422+
if not limit:
3423+
query = ""
3424+
limit = 0
34203425

3426+
if query is None:
34213427
if user_ids is None:
3422-
raise ValueError("Must pass either query or user_ids")
3428+
raise ValueError("Must pass query or user_ids, or set limit to None")
34233429

34243430
if user_ids is not None and query is not None:
34253431
raise ValueError("Cannot pass both query and user_ids")
34263432

34273433
if user_ids is not None and not user_ids:
34283434
raise ValueError("user_ids must contain at least 1 value")
34293435

3430-
limit = min(100, limit or 5)
34313436
return await self._state.query_members(
34323437
self,
34333438
query=query,

0 commit comments

Comments
 (0)