Skip to content

Commit 5d79d0e

Browse files
committed
refactor: Add missing with_counts parameter to guild retrieval methods
1 parent 72ba1b1 commit 5d79d0e

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

discord/client.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,7 @@ def fetch_guilds(
14621462
limit: int | None = 100,
14631463
before: SnowflakeTime = None,
14641464
after: SnowflakeTime = None,
1465+
with_counts: bool = False,
14651466
) -> GuildIterator:
14661467
"""Retrieves an :class:`.AsyncIterator` that enables receiving your guilds.
14671468
@@ -1489,6 +1490,10 @@ def fetch_guilds(
14891490
Retrieve guilds after this date or object.
14901491
If a datetime is provided, it is recommended to use a UTC aware datetime.
14911492
If the datetime is naive, it is assumed to be local time.
1493+
with_counts: Optional[:class:`bool`]
1494+
Whether to include count information in the guilds. This fills the
1495+
:attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count`
1496+
fields.
14921497
14931498
Yields
14941499
------
@@ -1835,8 +1840,8 @@ async def fetch_user(self, user_id: int, /) -> User:
18351840
return User(state=self._connection, data=data)
18361841

18371842
async def fetch_channel(
1838-
self, channel_id: int, /
1839-
) -> GuildChannel | PrivateChannel | Thread:
1843+
self, channel_id: int,
1844+
/) -> GuildChannel | PrivateChannel | Thread:
18401845
"""|coro|
18411846
18421847
Retrieves a :class:`.abc.GuildChannel`, :class:`.abc.PrivateChannel`, or :class:`.Thread` with the specified ID.

discord/http.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,7 @@ def get_guilds(
14451445
limit: int,
14461446
before: Snowflake | None = None,
14471447
after: Snowflake | None = None,
1448+
with_counts: bool = False,
14481449
) -> Response[list[guild.Guild]]:
14491450
params: dict[str, Any] = {
14501451
"limit": limit,
@@ -1454,6 +1455,8 @@ def get_guilds(
14541455
params["before"] = before
14551456
if after:
14561457
params["after"] = after
1458+
if with_counts:
1459+
params["with_counts"] = with_counts
14571460

14581461
return self.request(Route("GET", "/users/@me/guilds"), params=params)
14591462

@@ -3135,8 +3138,8 @@ def application_info(self) -> Response[appinfo.AppInfo]:
31353138
return self.request(Route("GET", "/oauth2/applications/@me"))
31363139

31373140
def get_application(
3138-
self, application_id: Snowflake, /
3139-
) -> Response[appinfo.PartialAppInfo]:
3141+
self, application_id: Snowflake,
3142+
/) -> Response[appinfo.PartialAppInfo]:
31403143
return self.request(
31413144
Route(
31423145
"GET",

discord/iterators.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ class GuildIterator(_AsyncIterator["Guild"]):
587587
Object after which all guilds must be.
588588
"""
589589

590-
def __init__(self, bot, limit, before=None, after=None):
590+
def __init__(self, bot, limit, before=None, after=None, with_counts=False):
591591
if isinstance(before, datetime.datetime):
592592
before = Object(id=time_snowflake(before, high=False))
593593
if isinstance(after, datetime.datetime):
@@ -597,6 +597,7 @@ def __init__(self, bot, limit, before=None, after=None):
597597
self.limit = limit
598598
self.before = before
599599
self.after = after
600+
self.with_counts = with_counts
600601

601602
self._filter = None
602603

@@ -654,7 +655,7 @@ async def _retrieve_guilds(self, retrieve) -> list[Guild]:
654655
async def _retrieve_guilds_before_strategy(self, retrieve):
655656
"""Retrieve guilds using before parameter."""
656657
before = self.before.id if self.before else None
657-
data: list[GuildPayload] = await self.get_guilds(retrieve, before=before)
658+
data: list[GuildPayload] = await self.get_guilds(retrieve, before=before, with_counts=self.with_counts)
658659
if len(data):
659660
if self.limit is not None:
660661
self.limit -= retrieve
@@ -664,7 +665,7 @@ async def _retrieve_guilds_before_strategy(self, retrieve):
664665
async def _retrieve_guilds_after_strategy(self, retrieve):
665666
"""Retrieve guilds using after parameter."""
666667
after = self.after.id if self.after else None
667-
data: list[GuildPayload] = await self.get_guilds(retrieve, after=after)
668+
data: list[GuildPayload] = await self.get_guilds(retrieve, after=after, with_counts=self.with_counts)
668669
if len(data):
669670
if self.limit is not None:
670671
self.limit -= retrieve

0 commit comments

Comments
 (0)