diff --git a/CHANGELOG.md b/CHANGELOG.md index 2bdd10e65d..9c6e30c8a5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -53,6 +53,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2417](https://github.com/Pycord-Development/pycord/pull/2417)) - `Option` may be used instead of `BridgeOption` until 2.7. ([#2417](https://github.com/Pycord-Development/pycord/pull/2417)) +- `Guild.query_members` now accepts `limit=None` to retrieve all members. + ([#2419](https://github.com/Pycord-Development/pycord/pull/2419)) ## [2.5.0] - 2024-03-02 diff --git a/discord/guild.py b/discord/guild.py index 6632743105..d94eb2df83 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -3361,7 +3361,7 @@ async def query_members( self, query: str | None = None, *, - limit: int = 5, + limit: int | None = 5, user_ids: list[int] | None = None, presences: bool = False, cache: bool = True, @@ -3379,10 +3379,14 @@ async def query_members( ---------- query: Optional[:class:`str`] The string that the username's start with. - limit: :class:`int` - The maximum number of members to send back. This must be - a number between 5 and 100. - presences: :class:`bool` + user_ids: Optional[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 + limit: Optional[:class:`int`] + The maximum number of members to send back. If no query is passed, passing ``None`` returns all members. + If a ``query`` or ``user_ids`` is passed, must be between 1 and 100. Defaults to 5. + presences: Optional[:class:`bool`] Whether to request for presences to be provided. This defaults to ``False``. @@ -3390,11 +3394,7 @@ async def query_members( cache: :class:`bool` Whether to cache the members internally. This makes operations - such as :meth:`get_member` work for those that matched. - user_ids: Optional[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 + such as :meth:`get_member` work for those that matched. Defaults to ``True``. Returns ------- @@ -3414,12 +3414,18 @@ async def query_members( if presences and not self._state._intents.presences: raise ClientException("Intents.presences must be enabled to use this.") - if query is None: - if query == "": - raise ValueError("Cannot pass empty query string.") + if not limit or limit > 100 or limit < 1: + if query or user_ids: + raise ValueError( + "limit must be between 1 and 100 when using query or user_ids" + ) + if not limit: + query = "" + limit = 0 + if query is None: if user_ids is None: - raise ValueError("Must pass either query or user_ids") + raise ValueError("Must pass query or user_ids, or set limit to None") if user_ids is not None and query is not None: raise ValueError("Cannot pass both query and user_ids") @@ -3427,7 +3433,6 @@ async def query_members( if user_ids is not None and not user_ids: raise ValueError("user_ids must contain at least 1 value") - limit = min(100, limit or 5) return await self._state.query_members( self, query=query,