Skip to content

Commit ee425c6

Browse files
committed
should get fetch_guild with with_counts working.
1 parent 16e7aff commit ee425c6

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

discord/client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,7 +1196,7 @@ async def fetch_template(self, code: Union[Template, str]) -> Template:
11961196
data = await self.http.get_template(code)
11971197
return Template(data=data, state=self._connection) # type: ignore
11981198

1199-
async def fetch_guild(self, guild_id: int, /) -> Guild:
1199+
async def fetch_guild(self, guild_id: int, /, *, with_counts=True) -> Guild:
12001200
"""|coro|
12011201
12021202
Retrieves a :class:`.Guild` from an ID.
@@ -1215,6 +1215,12 @@ async def fetch_guild(self, guild_id: int, /) -> Guild:
12151215
guild_id: :class:`int`
12161216
The guild's ID to fetch from.
12171217
1218+
with_counts: :class:`bool`
1219+
Whether to include count information in the guild. This fills the
1220+
:attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count`
1221+
fields.
1222+
1223+
12181224
Raises
12191225
------
12201226
:exc:`.Forbidden`
@@ -1227,7 +1233,7 @@ async def fetch_guild(self, guild_id: int, /) -> Guild:
12271233
:class:`.Guild`
12281234
The guild from the ID.
12291235
"""
1230-
data = await self.http.get_guild(guild_id)
1236+
data = await self.http.get_guild(guild_id, with_counts = with_counts)
12311237
return Guild(data=data, state=self._connection)
12321238

12331239
async def create_guild(

discord/guild.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ class Guild(Hashable):
296296
'_public_updates_channel_id',
297297
'_stage_instances',
298298
'_threads',
299+
"approximate_member_count",
300+
"approximate_presence_count"
299301
)
300302

301303
_PREMIUM_GUILD_LIMITS: ClassVar[Dict[Optional[int], _GuildLimit]] = {
@@ -464,6 +466,8 @@ def _from_data(self, guild: GuildPayload) -> None:
464466
self._rules_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'rules_channel_id')
465467
self._public_updates_channel_id: Optional[int] = utils._get_as_snowflake(guild, 'public_updates_channel_id')
466468
self.nsfw_level: NSFWLevel = try_enum(NSFWLevel, guild.get('nsfw_level', 0))
469+
self.approximate_presence_count = guild.get('approximate_presence_count')
470+
self.approximate_member_count = guild.get('approximate_member_count')
467471

468472
self._stage_instances: Dict[int, StageInstance] = {}
469473
for s in guild.get('stage_instances', []):

discord/http.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,8 +1100,9 @@ def get_guilds(
11001100
def leave_guild(self, guild_id: Snowflake) -> Response[None]:
11011101
return self.request(Route('DELETE', '/users/@me/guilds/{guild_id}', guild_id=guild_id))
11021102

1103-
def get_guild(self, guild_id: Snowflake) -> Response[guild.Guild]:
1104-
return self.request(Route('GET', '/guilds/{guild_id}', guild_id=guild_id))
1103+
def get_guild(self, guild_id: Snowflake, *, with_counts = True) -> Response[guild.Guild]:
1104+
params = {'with_counts': int(with_counts)}
1105+
return self.request(Route('GET', '/guilds/{guild_id}', guild_id=guild_id), params=params)
11051106

11061107
def delete_guild(self, guild_id: Snowflake) -> Response[None]:
11071108
return self.request(Route('DELETE', '/guilds/{guild_id}', guild_id=guild_id))

0 commit comments

Comments
 (0)