diff options
| author | unknown <[email protected]> | 2020-04-29 16:09:20 +0200 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2020-05-03 15:39:52 -0400 |
| commit | b7c7c86a6bcb39d2494499f709b1752ffac7d6af (patch) | |
| tree | 6358ca3d3c6cdd0627004db1108fa6a31465ea44 | |
| parent | Make use_cached keyword only (diff) | |
| download | discord.py-b7c7c86a6bcb39d2494499f709b1752ffac7d6af.tar.xz discord.py-b7c7c86a6bcb39d2494499f709b1752ffac7d6af.zip | |
Add roles parameter for pruning members.
| -rw-r--r-- | discord/guild.py | 15 | ||||
| -rw-r--r-- | discord/http.py | 5 |
2 files changed, 16 insertions, 4 deletions
diff --git a/discord/guild.py b/discord/guild.py index 204d617e..4ec93f68 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 8d2abfe0..7f249640 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) |