diff --git a/CHANGELOG.md b/CHANGELOG.md index c5696f04d6..c9ef9aaa98 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ These changes are available on the `master` branch, but have not yet been releas - Added `Attachment.read_chunked` and added optional `chunksize` argument to `Attachment.save` for retrieving attachments in chunks. ([#2956](https://github.com/Pycord-Development/pycord/pull/2956)) +- Added `Guild.fetch_roles_member_counts`. + ([#3020](https://github.com/Pycord-Development/pycord/pull/3020)) ### Changed diff --git a/discord/guild.py b/discord/guild.py index f910affe5c..57f0ab8f29 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1119,6 +1119,18 @@ def get_role(self, role_id: int, /) -> Role | None: """ return self._roles.get(role_id) + async def fetch_roles_member_counts(self) -> dict[int, int]: + """|coro| + Fetches a mapping of role IDs to their member counts for this guild. + + Returns + ------- + Dict[:class:`int`, :class:`int`] + A mapping of role IDs to their member counts. + """ + r = await self._state.http.get_roles_member_counts(self.id) + return {int(role_id): count for role_id, count in r.items()} + @property def default_role(self) -> Role: """Gets the @everyone role that all members have by default.""" diff --git a/discord/http.py b/discord/http.py index ae64703ba6..a131e598a7 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2145,6 +2145,11 @@ def delete_invite( def get_roles(self, guild_id: Snowflake) -> Response[list[role.Role]]: return self.request(Route("GET", "/guilds/{guild_id}/roles", guild_id=guild_id)) + def get_roles_member_counts(self, guild_id: Snowflake) -> Response[dict[str, int]]: + return self.request( + Route("GET", "/guilds/{guild_id}/roles/member-counts", guild_id=guild_id) + ) + def get_role(self, guild_id: Snowflake, role_id: Snowflake) -> Response[role.Role]: return self.request( Route(