Skip to content

Commit

Permalink
fix: Guild.query_members may accept empty query and limit (Pycord-Dev…
Browse files Browse the repository at this point in the history
…elopment#2419)

Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com>
Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com>
Co-authored-by: plun1331 <plun1331@gmail.com>
  • Loading branch information
5 people authored Apr 16, 2024
1 parent 929e15e commit f5683c5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 15 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
35 changes: 20 additions & 15 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -3379,22 +3379,22 @@ 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``.
.. versionadded:: 1.6
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
-------
Expand All @@ -3414,20 +3414,25 @@ 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")

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,
Expand Down

0 comments on commit f5683c5

Please sign in to comment.