Skip to content

Commit 48c5950

Browse files
BruhDarkpre-commit-ci[bot]DorukyumJustaSqu1d
authored
feat: add missing with_counts parameter to fetch_guilds method (#2615)
* refactor: Add missing `with_counts` parameter to guild retrieval methods * Default with_counts to True in fetch_guilds * Being dumb enough to forget about making it an int * style(pre-commit): auto fixes from pre-commit.com hooks * Update discord/client.py Co-authored-by: Dorukyum <[email protected]> Signed-off-by: Dark <[email protected]> * Update discord/iterators.py Co-authored-by: Dorukyum <[email protected]> Signed-off-by: Dark <[email protected]> * Update CHANGELOG.md * Update discord/client.py Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: Dark <[email protected]> * Update discord/iterators.py Co-authored-by: JustaSqu1d <[email protected]> Signed-off-by: Dark <[email protected]> --------- Signed-off-by: Dark <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Dorukyum <[email protected]> Co-authored-by: JustaSqu1d <[email protected]>
1 parent 05cf45e commit 48c5950

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ These changes are available on the `master` branch, but have not yet been releas
3030
([#2587](https://github.com/Pycord-Development/pycord/pull/2587/))
3131
- Added optional `filter` parameter to `utils.basic_autocomplete()`.
3232
([#2590](https://github.com/Pycord-Development/pycord/pull/2590))
33+
- Added missing `with_counts` parameter to `fetch_guilds` method.
34+
([#2615](https://github.com/Pycord-Development/pycord/pull/2615))
3335

3436
### Fixed
3537

discord/client.py

Lines changed: 9 additions & 1 deletion
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 = True,
14651466
) -> GuildIterator:
14661467
"""Retrieves an :class:`.AsyncIterator` that enables receiving your guilds.
14671468
@@ -1489,6 +1490,11 @@ 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: :class:`bool`
1494+
Whether to include member count information in guilds. This fills the
1495+
:attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count`
1496+
fields.
1497+
Defaults to ``True``.
14921498
14931499
Yields
14941500
------
@@ -1515,7 +1521,9 @@ def fetch_guilds(
15151521
15161522
All parameters are optional.
15171523
"""
1518-
return GuildIterator(self, limit=limit, before=before, after=after)
1524+
return GuildIterator(
1525+
self, limit=limit, before=before, after=after, with_counts=with_counts
1526+
)
15191527

15201528
async def fetch_template(self, code: Template | str) -> Template:
15211529
"""|coro|

discord/http.py

Lines changed: 3 additions & 0 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 = True,
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"] = int(with_counts)
14571460

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

discord/iterators.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -585,9 +585,14 @@ class GuildIterator(_AsyncIterator["Guild"]):
585585
Object before which all guilds must be.
586586
after: Optional[Union[:class:`abc.Snowflake`, :class:`datetime.datetime`]]
587587
Object after which all guilds must be.
588+
with_counts: :class:`bool`
589+
Whether to include member count information in guilds. This fills the
590+
:attr:`.Guild.approximate_member_count` and :attr:`.Guild.approximate_presence_count`
591+
fields.
592+
Defaults to ``True``.
588593
"""
589594

590-
def __init__(self, bot, limit, before=None, after=None):
595+
def __init__(self, bot, limit, before=None, after=None, with_counts=True):
591596
if isinstance(before, datetime.datetime):
592597
before = Object(id=time_snowflake(before, high=False))
593598
if isinstance(after, datetime.datetime):
@@ -597,6 +602,7 @@ def __init__(self, bot, limit, before=None, after=None):
597602
self.limit = limit
598603
self.before = before
599604
self.after = after
605+
self.with_counts = with_counts
600606

601607
self._filter = None
602608

@@ -654,7 +660,9 @@ async def _retrieve_guilds(self, retrieve) -> list[Guild]:
654660
async def _retrieve_guilds_before_strategy(self, retrieve):
655661
"""Retrieve guilds using before parameter."""
656662
before = self.before.id if self.before else None
657-
data: list[GuildPayload] = await self.get_guilds(retrieve, before=before)
663+
data: list[GuildPayload] = await self.get_guilds(
664+
retrieve, before=before, with_counts=self.with_counts
665+
)
658666
if len(data):
659667
if self.limit is not None:
660668
self.limit -= retrieve
@@ -664,7 +672,9 @@ async def _retrieve_guilds_before_strategy(self, retrieve):
664672
async def _retrieve_guilds_after_strategy(self, retrieve):
665673
"""Retrieve guilds using after parameter."""
666674
after = self.after.id if self.after else None
667-
data: list[GuildPayload] = await self.get_guilds(retrieve, after=after)
675+
data: list[GuildPayload] = await self.get_guilds(
676+
retrieve, after=after, with_counts=self.with_counts
677+
)
668678
if len(data):
669679
if self.limit is not None:
670680
self.limit -= retrieve

0 commit comments

Comments
 (0)