@@ -3820,6 +3820,43 @@ async def fetch_roles(self) -> list[Role]:
38203820 data = await self ._state .http .get_roles (self .id )
38213821 return [Role (guild = self , state = self ._state , data = d ) for d in data ]
38223822
3823+ async def fetch_role_member_counts (self ) -> dict [Role | Object , int ]:
3824+ r"""|coro|
3825+
3826+ Retrieves the member counts of all :class:`Role`\s that the guild has.
3827+
3828+ .. caution::
3829+ This uses an endpoint that is currently in public preview,
3830+ it should not be considered stable and is exempt from version guarantees:
3831+ https://github.com/discord/discord-api-docs/discussions/3306#discussioncomment-14681890.
3832+
3833+ .. note::
3834+
3835+ This method is an API call. For general usage, consider :attr:`roles` instead.
3836+
3837+ .. versionadded:: |vnext|
3838+
3839+ Raises
3840+ ------
3841+ HTTPException
3842+ Retrieving the role member counts failed.
3843+
3844+ Returns
3845+ -------
3846+ :class:`dict`\[:class:`Role` | :class:`Object`, :class:`int`]
3847+ The member counts of the roles.
3848+ Roles that could not be found in the bot's cache are
3849+ :class:`Object` with the corresponding ID instead.
3850+ """
3851+ data = await self ._state .http .get_role_member_counts (self .id )
3852+ counts : dict [Role | Object , int ] = {}
3853+ for id_str , count in data .items ():
3854+ id = int (id_str )
3855+ obj = self .get_role (id ) or Object (id )
3856+ counts [obj ] = count
3857+
3858+ return counts
3859+
38233860 @overload
38243861 async def get_or_fetch_member (
38253862 self , member_id : int , * , strict : Literal [False ] = ...
0 commit comments