From fbb7ac6be144d9371c9a67735c80bb787d09673a Mon Sep 17 00:00:00 2001 From: z03h Date: Wed, 24 Mar 2021 05:17:34 -0700 Subject: [PATCH] Add roles to guild.estimate_pruned_members --- discord/guild.py | 12 ++++++++++-- discord/http.py | 5 ++++- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 92d9a59e7..9610cdeab 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1506,7 +1506,7 @@ class Guild(Hashable): data = await self._state.http.guild_webhooks(self.id) return [Webhook.from_state(d, state=self._state) for d in data] - async def estimate_pruned_members(self, *, days): + async def estimate_pruned_members(self, *, days, roles=None): """|coro| Similar to :meth:`prune_members` except instead of actually @@ -1517,6 +1517,11 @@ class Guild(Hashable): ----------- days: :class:`int` The number of days before counting as inactive. + roles: Optional[List[:class:`abc.Snowflake`]] + A list of :class:`abc.Snowflake` that represent roles to include in the estimate. If a member + has a role that is not specified, they'll be excluded. + + .. versionadded:: 1.7 Raises ------- @@ -1536,7 +1541,10 @@ class Guild(Hashable): if not isinstance(days, int): raise InvalidArgument('Expected int for ``days``, received {0.__class__.__name__} instead.'.format(days)) - data = await self._state.http.estimate_pruned_members(self.id, days) + if roles: + roles = [str(role.id) for role in roles] + + data = await self._state.http.estimate_pruned_members(self.id, days, roles) return data['pruned'] async def invites(self): diff --git a/discord/http.py b/discord/http.py index 43f01d759..5a5820bd5 100644 --- a/discord/http.py +++ b/discord/http.py @@ -739,10 +739,13 @@ class HTTPClient: return self.request(Route('POST', '/guilds/{guild_id}/prune', guild_id=guild_id), json=payload, reason=reason) - def estimate_pruned_members(self, guild_id, days): + def estimate_pruned_members(self, guild_id, days, roles): params = { 'days': days } + if roles: + params['include_roles'] = ', '.join(roles) + return self.request(Route('GET', '/guilds/{guild_id}/prune', guild_id=guild_id), params=params) def get_all_custom_emojis(self, guild_id):