Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 12 additions & 0 deletions discord/guild.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()}
Comment on lines +1122 to +1132
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be a better ux if we map it to Role: count instead of only the IDs? The role should be cached anyways, but we can fall back to Object if needed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did think about that. I'm going to see again for mapping a role object, it just seemed weird to me but we could do that. As for Role.count I don't think that would be a good thing, it's not really what it is, you get it separately, it's not on the role object.

Copy link
Contributor

@Soheab Soheab Dec 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, no Role.count wouldn't make sense and potentially even footgun us when Discord makes that an actual thing but with a different purpose.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing with mapping ROle / Object instead of id is that it would force the user to create a discord.Object if they only have an id


@property
def default_role(self) -> Role:
"""Gets the @everyone role that all members have by default."""
Expand Down
5 changes: 5 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Loading