From b7c7c86a6bcb39d2494499f709b1752ffac7d6af Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 29 Apr 2020 16:09:20 +0200 Subject: [PATCH] Add roles parameter for pruning members. --- discord/guild.py | 15 +++++++++++++-- discord/http.py | 5 +++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/discord/guild.py b/discord/guild.py index 204d617ed..4ec93f683 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -1282,7 +1282,7 @@ class Guild(Hashable): reason=e['reason']) for e in data] - async def prune_members(self, *, days, compute_prune_count=True, reason=None): + async def prune_members(self, *, days, compute_prune_count=True, roles=None, reason=None): r"""|coro| Prunes the guild from its inactive members. @@ -1296,6 +1296,11 @@ class Guild(Hashable): To check how many members you would prune without actually pruning, see the :meth:`estimate_pruned_members` function. + To prune members that have specific roles see the ``roles`` parameter. + + .. versionchanged:: 1.4 + The ``roles`` keyword-only parameter was added. + Parameters ----------- days: :class:`int` @@ -1307,6 +1312,9 @@ class Guild(Hashable): which makes it prone to timeouts in very large guilds. In order to prevent timeouts, you must set this to ``False``. If this is set to ``False``\, then this function will always return ``None``. + roles: Optional[List[:class:`abc.Snowflake`]] + A list of :class:`abc.Snowflake` that represent roles to include in the pruning process. If a member + has a role that is not specified, they'll be excluded. Raises ------- @@ -1327,7 +1335,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.prune_members(self.id, days, compute_prune_count=compute_prune_count, reason=reason) + if roles: + roles = [role.id for role in roles] + + data = await self._state.http.prune_members(self.id, days, compute_prune_count=compute_prune_count, roles=roles, reason=reason) return data['pruned'] async def webhooks(self): diff --git a/discord/http.py b/discord/http.py index 8d2abfe01..7f2496400 100644 --- a/discord/http.py +++ b/discord/http.py @@ -657,10 +657,11 @@ class HTTPClient: def get_member(self, guild_id, member_id): return self.request(Route('GET', '/guilds/{guild_id}/members/{member_id}', guild_id=guild_id, member_id=member_id)) - def prune_members(self, guild_id, days, compute_prune_count, *, reason=None): + def prune_members(self, guild_id, days, compute_prune_count, roles, *, reason=None): params = { 'days': days, - 'compute_prune_count': 'true' if compute_prune_count else 'false' + 'compute_prune_count': 'true' if compute_prune_count else 'false', + 'include_roles': roles } return self.request(Route('POST', '/guilds/{guild_id}/prune', guild_id=guild_id), params=params, reason=reason)