Add support for role member counts

This commit is contained in:
Rapptz
2025-10-16 02:23:49 -04:00
parent c58b973c7e
commit ab8195bbd3
2 changed files with 36 additions and 0 deletions

View File

@@ -3872,6 +3872,39 @@ class Guild(Hashable):
return roles
async def role_member_counts(self) -> Dict[Union[Object, Role], int]:
"""|coro|
Retrieves a mapping of roles to the number of members that have it.
You must have :attr:`~Permissions.manage_roles` to do this.
.. versionadded:: 2.7
Raises
-------
Forbidden
You do not have permissions to view the role member counts.
HTTPException
Retrieving the role member counts failed.
Returns
--------
Dict[Union[:class:`Object`, :class:`Role`], :class:`int`]
A mapping of roles to the number of members that have it.
If a role is not found in the cache, it will be represented as an :class:`Object`
instead of a :class:`Role`.
"""
data = await self._state.http.get_role_member_counts(self.id)
result: Dict[Union[Object, Role], int] = {}
for role_id, member_count in data.items():
role_id = int(role_id)
role = self.get_role(role_id)
if role is None:
role = Object(id=role_id, type=Role)
result[role] = member_count
return result
async def welcome_screen(self) -> WelcomeScreen:
"""|coro|