From 032f05527cc70a82f35a27f24fe7415421236463 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 2 Nov 2021 11:04:00 -0400 Subject: [PATCH 01/11] Update utils.py Someone complained it now being '' so I made it as such, I can revert it back if an issue --- discord/utils.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/discord/utils.py b/discord/utils.py index 38f11d4281..1266247268 100644 --- a/discord/utils.py +++ b/discord/utils.py @@ -74,19 +74,19 @@ __all__ = ( - "oauth_url", - "snowflake_time", - "time_snowflake", - "find", - "get", - "sleep_until", - "utcnow", - "remove_markdown", - "escape_markdown", - "escape_mentions", - "as_chunks", - "format_dt", - "generate_snowflake", + 'oauth_url', + 'snowflake_time', + 'time_snowflake', + 'find', + 'get', + 'sleep_until', + 'utcnow', + 'remove_markdown', + 'escape_markdown', + 'escape_mentions', + 'as_chunks', + 'format_dt', + 'generate_snowflake', ) DISCORD_EPOCH = 1420070400000 @@ -1102,4 +1102,4 @@ async def autocomplete_callback(interaction: Interaction, _values = await _values return ([x for x in _values if x.lower().startswith(value.lower())])[:25] - return autocomplete_callback \ No newline at end of file + return autocomplete_callback From ee425c6c2ae7b90fffc2267cc4475bba1209f225 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 02:29:54 -0500 Subject: [PATCH 02/11] should get fetch_guild with with_counts working. --- discord/client.py | 10 ++++++++-- discord/guild.py | 4 ++++ discord/http.py | 5 +++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/discord/client.py b/discord/client.py index 93c4857c42..f21e4a9c82 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1196,7 +1196,7 @@ async def fetch_template(self, code: Union[Template, str]) -> Template: data = await self.http.get_template(code) return Template(data=data, state=self._connection) # type: ignore - async def fetch_guild(self, guild_id: int, /) -> Guild: + async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild: """|coro| Retrieves a :class:`.Guild` from an ID. @@ -1215,6 +1215,12 @@ async def fetch_guild(self, guild_id: int, /) -> Guild: guild_id: :class:`int` The guild's ID to fetch from. + with_counts: :class:`bool` + Whether to include count information in the guild. This fills the + :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` + fields. + + Raises ------ :exc:`.Forbidden` @@ -1227,7 +1233,7 @@ async def fetch_guild(self, guild_id: int, /) -> Guild: :class:`.Guild` The guild from the ID. """ - data = await self.http.get_guild(guild_id) + data = await self.http.get_guild(guild_id, with_counts = with_counts) return Guild(data=data, state=self._connection) async def create_guild( diff --git a/discord/guild.py b/discord/guild.py index a52fefec27..e9ce76e44d 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -296,6 +296,8 @@ class Guild(Hashable): '_public_updates_channel_id', '_stage_instances', '_threads', + "approximate_member_count", + "approximate_presence_count" ) _PREMIUM_GUILD_LIMITS: ClassVar[Dict[Optional[int], _GuildLimit]] = { @@ -464,6 +466,8 @@ def _from_data(self, guild: GuildPayload) -> None: self._rules_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'rules_channel_id') self._public_updates_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'public_updates_channel_id') self.nsfw_level: NSFWLevel = try_enum(NSFWLevel, guild.get('nsfw_level', 0)) + self.approximate_presence_count = guild.get('approximate_presence_count') + self.approximate_member_count = guild.get('approximate_member_count') self._stage_instances: Dict[int, StageInstance] = {} for s in guild.get('stage_instances', []): diff --git a/discord/http.py b/discord/http.py index 4b8ff6aa81..ffbadcad8c 100644 --- a/discord/http.py +++ b/discord/http.py @@ -1100,8 +1100,9 @@ def get_guilds( def leave_guild(self, guild_id: Snowflake) -> Response[None]: return self.request(Route('DELETE', '/users/@me/guilds/{guild_id}', guild_id=guild_id)) - def get_guild(self, guild_id: Snowflake) -> Response[guild.Guild]: - return self.request(Route('GET', '/guilds/{guild_id}', guild_id=guild_id)) + def get_guild(self, guild_id: Snowflake, *, with_counts = True) -> Response[guild.Guild]: + params = {'with_counts': int(with_counts)} + return self.request(Route('GET', '/guilds/{guild_id}', guild_id=guild_id), params=params) def delete_guild(self, guild_id: Snowflake) -> Response[None]: return self.request(Route('DELETE', '/guilds/{guild_id}', guild_id=guild_id)) From 85c6f714050fdee9d638151691b5bcf99b2cc352 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 02:57:55 -0500 Subject: [PATCH 03/11] Update client.py --- discord/client.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/discord/client.py b/discord/client.py index f21e4a9c82..bd73b38696 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1219,6 +1219,8 @@ async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild: Whether to include count information in the guild. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. + + .. versionadded:: 2.0 Raises From 10a073cef144299f7dd542f6cef28c361520c977 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:00:38 -0500 Subject: [PATCH 04/11] Update guild.py --- discord/guild.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/discord/guild.py b/discord/guild.py index e9ce76e44d..3e12a1a6ac 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -253,6 +253,18 @@ class Guild(Hashable): The guild's NSFW level. .. versionadded:: 2.0 + + approximate_member_count: Optional[:class:`int`] + The approximate number of members in the guild. This is ``None`` unless the guild is obtained + using :meth:`Client.fetch_guild` with ``with_counts=True``. + .. versionadded:: 2.0 + + approximate_presence_count: Optional[:class:`int`] + The approximate number of members currently active in the guild. + This includes idle, dnd, online, and invisible members. Offline members are excluded. + This is ``None`` unless the guild is obtained using :meth:`Client.fetch_guild` + with ``with_counts=True``. + .. versionadded:: 2.0 """ __slots__ = ( From 080799ef53608186c79570eefb9be517bc050e5b Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:03:55 -0500 Subject: [PATCH 05/11] Update client.py --- discord/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index bd73b38696..99f1554f86 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1219,7 +1219,6 @@ async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild: Whether to include count information in the guild. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. - .. versionadded:: 2.0 From cc4a616c77f04da09c94c81176a686a2afac2ac5 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:04:04 -0500 Subject: [PATCH 06/11] Update discord/guild.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index 3e12a1a6ac..2963a4cf88 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -254,7 +254,7 @@ class Guild(Hashable): .. versionadded:: 2.0 - approximate_member_count: Optional[:class:`int`] + approximate_member_count: Optional[:class:`int`] The approximate number of members in the guild. This is ``None`` unless the guild is obtained using :meth:`Client.fetch_guild` with ``with_counts=True``. .. versionadded:: 2.0 From 54317ec84e0405eab5fcf839f20630bb15d94b72 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:04:34 -0500 Subject: [PATCH 07/11] Update discord/guild.py Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/guild.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/guild.py b/discord/guild.py index 2963a4cf88..3a5bd1a5ea 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -309,7 +309,7 @@ class Guild(Hashable): '_stage_instances', '_threads', "approximate_member_count", - "approximate_presence_count" + "approximate_presence_count", ) _PREMIUM_GUILD_LIMITS: ClassVar[Dict[Optional[int], _GuildLimit]] = { From d9a78c28dddc4b77d8bfb6e2d00117b7361378b0 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:08:10 -0500 Subject: [PATCH 08/11] Update discord/guild.py Co-authored-by: Lala Sabathil --- discord/guild.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/guild.py b/discord/guild.py index 3a5bd1a5ea..7a505cebca 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -257,6 +257,7 @@ class Guild(Hashable): approximate_member_count: Optional[:class:`int`] The approximate number of members in the guild. This is ``None`` unless the guild is obtained using :meth:`Client.fetch_guild` with ``with_counts=True``. + .. versionadded:: 2.0 approximate_presence_count: Optional[:class:`int`] From b7c2bb972b7622e4999b11f991905d4c8e097e07 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:08:19 -0500 Subject: [PATCH 09/11] Update discord/client.py Co-authored-by: Lala Sabathil --- discord/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 99f1554f86..0c66227f60 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1219,8 +1219,8 @@ async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild: Whether to include count information in the guild. This fills the :attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count` fields. - .. versionadded:: 2.0 + .. versionadded:: 2.0 Raises ------ From 6f3d4aacd61ac5f5a86e974afb8b09ce94060e46 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:08:25 -0500 Subject: [PATCH 10/11] Update discord/client.py Co-authored-by: Lala Sabathil --- discord/client.py | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 0c66227f60..bcaff2cd7e 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1221,7 +1221,6 @@ async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild: fields. .. versionadded:: 2.0 - Raises ------ :exc:`.Forbidden` From 2d42833173f500971be7c5d4481996e5fd5e87a9 Mon Sep 17 00:00:00 2001 From: "JDJG Inc. Official" Date: Tue, 16 Nov 2021 03:08:32 -0500 Subject: [PATCH 11/11] Update discord/guild.py Co-authored-by: Lala Sabathil --- discord/guild.py | 1 + 1 file changed, 1 insertion(+) diff --git a/discord/guild.py b/discord/guild.py index 7a505cebca..3f70a851fc 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -265,6 +265,7 @@ class Guild(Hashable): This includes idle, dnd, online, and invisible members. Offline members are excluded. This is ``None`` unless the guild is obtained using :meth:`Client.fetch_guild` with ``with_counts=True``. + .. versionadded:: 2.0 """