From 5d79d0e85f3195c1f623ceb18ba5309a96c37831 Mon Sep 17 00:00:00 2001 From: Dark Date: Mon, 21 Oct 2024 01:07:24 -0300 Subject: [PATCH 1/9] refactor: Add missing `with_counts` parameter to guild retrieval methods --- discord/client.py | 9 +++++++-- discord/http.py | 7 +++++-- discord/iterators.py | 7 ++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/discord/client.py b/discord/client.py index 8ece21cf94..88b852583c 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1462,6 +1462,7 @@ def fetch_guilds( limit: int | None = 100, before: SnowflakeTime = None, after: SnowflakeTime = None, + with_counts: bool = False, ) -> GuildIterator: """Retrieves an :class:`.AsyncIterator` that enables receiving your guilds. @@ -1489,6 +1490,10 @@ def fetch_guilds( Retrieve guilds after this date or object. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. + with_counts: Optional[:class:`bool`] + Whether to include count information in the guilds. This fills the + :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` + fields. Yields ------ @@ -1835,8 +1840,8 @@ async def fetch_user(self, user_id: int, /) -> User: return User(state=self._connection, data=data) async def fetch_channel( - self, channel_id: int, / - ) -> GuildChannel | PrivateChannel | Thread: + self, channel_id: int, + /) -> GuildChannel | PrivateChannel | Thread: """|coro| Retrieves a :class:`.abc.GuildChannel`, :class:`.abc.PrivateChannel`, or :class:`.Thread` with the specified ID. diff --git a/discord/http.py b/discord/http.py index 26b584ba7e..a9a28bf75a 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1445,6 +1445,7 @@ def get_guilds( limit: int, before: Snowflake | None = None, after: Snowflake | None = None, + with_counts: bool = False, ) -> Response[list[guild.Guild]]: params: dict[str, Any] = { "limit": limit, @@ -1454,6 +1455,8 @@ def get_guilds( params["before"] = before if after: params["after"] = after + if with_counts: + params["with_counts"] = with_counts return self.request(Route("GET", "/users/@me/guilds"), params=params) @@ -3135,8 +3138,8 @@ def application_info(self) -> Response[appinfo.AppInfo]: return self.request(Route("GET", "/oauth2/applications/@me")) def get_application( - self, application_id: Snowflake, / - ) -> Response[appinfo.PartialAppInfo]: + self, application_id: Snowflake, + /) -> Response[appinfo.PartialAppInfo]: return self.request( Route( "GET", diff --git a/discord/iterators.py b/discord/iterators.py index 13f67266ea..47b9669ae4 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -587,7 +587,7 @@ class GuildIterator(_AsyncIterator["Guild"]): Object after which all guilds must be. """ - def __init__(self, bot, limit, before=None, after=None): + def __init__(self, bot, limit, before=None, after=None, with_counts=False): if isinstance(before, datetime.datetime): before = Object(id=time_snowflake(before, high=False)) if isinstance(after, datetime.datetime): @@ -597,6 +597,7 @@ def __init__(self, bot, limit, before=None, after=None): self.limit = limit self.before = before self.after = after + self.with_counts = with_counts self._filter = None @@ -654,7 +655,7 @@ async def _retrieve_guilds(self, retrieve) -> list[Guild]: async def _retrieve_guilds_before_strategy(self, retrieve): """Retrieve guilds using before parameter.""" before = self.before.id if self.before else None - data: list[GuildPayload] = await self.get_guilds(retrieve, before=before) + data: list[GuildPayload] = await self.get_guilds(retrieve, before=before, with_counts=self.with_counts) if len(data): if self.limit is not None: self.limit -= retrieve @@ -664,7 +665,7 @@ async def _retrieve_guilds_before_strategy(self, retrieve): async def _retrieve_guilds_after_strategy(self, retrieve): """Retrieve guilds using after parameter.""" after = self.after.id if self.after else None - data: list[GuildPayload] = await self.get_guilds(retrieve, after=after) + data: list[GuildPayload] = await self.get_guilds(retrieve, after=after, with_counts=self.with_counts) if len(data): if self.limit is not None: self.limit -= retrieve From ed069c25677525856494daec761834c93865ba39 Mon Sep 17 00:00:00 2001 From: Dark Date: Mon, 21 Oct 2024 01:34:47 -0300 Subject: [PATCH 2/9] Default with_counts to True in fetch_guilds --- discord/client.py | 5 +++-- discord/http.py | 2 +- discord/iterators.py | 7 ++++++- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/discord/client.py b/discord/client.py index 88b852583c..569f7d9212 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1462,7 +1462,7 @@ def fetch_guilds( limit: int | None = 100, before: SnowflakeTime = None, after: SnowflakeTime = None, - with_counts: bool = False, + with_counts: bool = True, ) -> GuildIterator: """Retrieves an :class:`.AsyncIterator` that enables receiving your guilds. @@ -1494,6 +1494,7 @@ def fetch_guilds( Whether to include count information in the guilds. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. + Defaults to ``True``. Yields ------ @@ -1520,7 +1521,7 @@ def fetch_guilds( All parameters are optional. """ - return GuildIterator(self, limit=limit, before=before, after=after) + return GuildIterator(self, limit=limit, before=before, after=after, with_counts=with_counts) async def fetch_template(self, code: Template | str) -> Template: """|coro| diff --git a/discord/http.py b/discord/http.py index a9a28bf75a..ee6b828ff0 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1445,7 +1445,7 @@ def get_guilds( limit: int, before: Snowflake | None = None, after: Snowflake | None = None, - with_counts: bool = False, + with_counts: bool = True, ) -> Response[list[guild.Guild]]: params: dict[str, Any] = { "limit": limit, diff --git a/discord/iterators.py b/discord/iterators.py index 47b9669ae4..dce2205781 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -585,9 +585,14 @@ class GuildIterator(_AsyncIterator["Guild"]): Object before which all guilds must be. after: Optional[Union[:class:`abc.Snowflake`, :class:`datetime.datetime`]] Object after which all guilds must be. + with_counts: Optional[:class:`bool`] + Whether to include count information in the guilds. This fills the + :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` + fields. + Defaults to ``True``. """ - def __init__(self, bot, limit, before=None, after=None, with_counts=False): + def __init__(self, bot, limit, before=None, after=None, with_counts=True): if isinstance(before, datetime.datetime): before = Object(id=time_snowflake(before, high=False)) if isinstance(after, datetime.datetime): From 60e9226e3421fa9f13d09c2a8c8950b808a4c055 Mon Sep 17 00:00:00 2001 From: Dark Date: Mon, 21 Oct 2024 01:42:37 -0300 Subject: [PATCH 3/9] Being dumb enough to forget about making it an int --- discord/http.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/http.py b/discord/http.py index ee6b828ff0..950e216421 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1456,7 +1456,7 @@ def get_guilds( if after: params["after"] = after if with_counts: - params["with_counts"] = with_counts + params["with_counts"] = int(with_counts) return self.request(Route("GET", "/users/@me/guilds"), params=params) From 8132afc4748e8e62629a45e215bfedf811815dd0 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 21 Oct 2024 04:55:21 +0000 Subject: [PATCH 4/9] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/client.py | 8 +++++--- discord/http.py | 4 ++-- discord/iterators.py | 8 ++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/discord/client.py b/discord/client.py index 569f7d9212..6ce7d86107 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1521,7 +1521,9 @@ def fetch_guilds( All parameters are optional. """ - return GuildIterator(self, limit=limit, before=before, after=after, with_counts=with_counts) + return GuildIterator( + self, limit=limit, before=before, after=after, with_counts=with_counts + ) async def fetch_template(self, code: Template | str) -> Template: """|coro| @@ -1841,8 +1843,8 @@ async def fetch_user(self, user_id: int, /) -> User: return User(state=self._connection, data=data) async def fetch_channel( - self, channel_id: int, - /) -> GuildChannel | PrivateChannel | Thread: + self, channel_id: int, / + ) -> GuildChannel | PrivateChannel | Thread: """|coro| Retrieves a :class:`.abc.GuildChannel`, :class:`.abc.PrivateChannel`, or :class:`.Thread` with the specified ID. diff --git a/discord/http.py b/discord/http.py index 950e216421..3a7cf1410d 100644 --- a/discord/http.py +++ b/discord/http.py @@ -3138,8 +3138,8 @@ def application_info(self) -> Response[appinfo.AppInfo]: return self.request(Route("GET", "/oauth2/applications/@me")) def get_application( - self, application_id: Snowflake, - /) -> Response[appinfo.PartialAppInfo]: + self, application_id: Snowflake, / + ) -> Response[appinfo.PartialAppInfo]: return self.request( Route( "GET", diff --git a/discord/iterators.py b/discord/iterators.py index dce2205781..0e1a564eab 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -660,7 +660,9 @@ async def _retrieve_guilds(self, retrieve) -> list[Guild]: async def _retrieve_guilds_before_strategy(self, retrieve): """Retrieve guilds using before parameter.""" before = self.before.id if self.before else None - data: list[GuildPayload] = await self.get_guilds(retrieve, before=before, with_counts=self.with_counts) + data: list[GuildPayload] = await self.get_guilds( + retrieve, before=before, with_counts=self.with_counts + ) if len(data): if self.limit is not None: self.limit -= retrieve @@ -670,7 +672,9 @@ async def _retrieve_guilds_before_strategy(self, retrieve): async def _retrieve_guilds_after_strategy(self, retrieve): """Retrieve guilds using after parameter.""" after = self.after.id if self.after else None - data: list[GuildPayload] = await self.get_guilds(retrieve, after=after, with_counts=self.with_counts) + data: list[GuildPayload] = await self.get_guilds( + retrieve, after=after, with_counts=self.with_counts + ) if len(data): if self.limit is not None: self.limit -= retrieve From 05d1fc23fc34b66ac29a7fdf7caf90f7a48d0686 Mon Sep 17 00:00:00 2001 From: Dark <58370174+BruhDark@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:01:48 -0300 Subject: [PATCH 5/9] Update discord/client.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Dark <58370174+BruhDark@users.noreply.github.com> --- discord/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 6ce7d86107..32b73583d7 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1490,7 +1490,7 @@ def fetch_guilds( Retrieve guilds after this date or object. If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. - with_counts: Optional[:class:`bool`] + with_counts: :class:`bool` Whether to include count information in the guilds. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. From 5c791f196c45219baa567173edcfe08b27c53b43 Mon Sep 17 00:00:00 2001 From: Dark <58370174+BruhDark@users.noreply.github.com> Date: Mon, 21 Oct 2024 11:01:58 -0300 Subject: [PATCH 6/9] Update discord/iterators.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: Dark <58370174+BruhDark@users.noreply.github.com> --- discord/iterators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/iterators.py b/discord/iterators.py index 0e1a564eab..e36c51567b 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -585,7 +585,7 @@ class GuildIterator(_AsyncIterator["Guild"]): Object before which all guilds must be. after: Optional[Union[:class:`abc.Snowflake`, :class:`datetime.datetime`]] Object after which all guilds must be. - with_counts: Optional[:class:`bool`] + with_counts: :class:`bool` Whether to include count information in the guilds. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. From fc6078394e3f4cdd8258d0ace612ef472c6e35af Mon Sep 17 00:00:00 2001 From: Dark Date: Mon, 21 Oct 2024 11:04:39 -0300 Subject: [PATCH 7/9] Update CHANGELOG.md --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7da04a101a..de672a1944 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2587](https://github.com/Pycord-Development/pycord/pull/2587/)) - Added optional `filter` parameter to `utils.basic_autocomplete()`. ([#2590](https://github.com/Pycord-Development/pycord/pull/2590)) +- Added missing `with_counts` parameter to `fetch_guilds` method. + ([#2615](https://github.com/Pycord-Development/pycord/pull/2615)) ### Fixed From a00451a3f6ccbf715ef3275a065008432747c5e3 Mon Sep 17 00:00:00 2001 From: Dark <58370174+BruhDark@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:15:39 -0300 Subject: [PATCH 8/9] Update discord/client.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Dark <58370174+BruhDark@users.noreply.github.com> --- discord/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 32b73583d7..741c113b42 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1491,7 +1491,7 @@ def fetch_guilds( If a datetime is provided, it is recommended to use a UTC aware datetime. If the datetime is naive, it is assumed to be local time. with_counts: :class:`bool` - Whether to include count information in the guilds. This fills the + Whether to include member count information in guilds. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. Defaults to ``True``. From 0b167f6abb9d51cb058142afebc2c58e7a13d3f7 Mon Sep 17 00:00:00 2001 From: Dark <58370174+BruhDark@users.noreply.github.com> Date: Fri, 25 Oct 2024 19:15:47 -0300 Subject: [PATCH 9/9] Update discord/iterators.py Co-authored-by: JustaSqu1d <89910983+JustaSqu1d@users.noreply.github.com> Signed-off-by: Dark <58370174+BruhDark@users.noreply.github.com> --- discord/iterators.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/iterators.py b/discord/iterators.py index e36c51567b..eca3c72091 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -586,7 +586,7 @@ class GuildIterator(_AsyncIterator["Guild"]): after: Optional[Union[:class:`abc.Snowflake`, :class:`datetime.datetime`]] Object after which all guilds must be. with_counts: :class:`bool` - Whether to include count information in the guilds. This fills the + Whether to include member count information in guilds. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. Defaults to ``True``.