diff options
| author | Rapptz <[email protected]> | 2016-07-29 14:40:30 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2016-07-29 14:40:30 -0400 |
| commit | 667d2b384beb967a3ce5ee9c307a740d1357f59e (patch) | |
| tree | 79a669a3154e67fd665d7be7d71b9213573156de /discord/client.py | |
| parent | Clarify that Client.purge_from requires Manage Messages for anything. (diff) | |
| download | discord.py-667d2b384beb967a3ce5ee9c307a740d1357f59e.tar.xz discord.py-667d2b384beb967a3ce5ee9c307a740d1357f59e.zip | |
Add functions to query and actually prune members from a server.
Diffstat (limited to 'discord/client.py')
| -rw-r--r-- | discord/client.py | 79 |
1 files changed, 78 insertions, 1 deletions
diff --git a/discord/client.py b/discord/client.py index c07ada45..b8edff24 100644 --- a/discord/client.py +++ b/discord/client.py @@ -1954,7 +1954,6 @@ class Client: yield from self.http.edit_server(server.id, **fields) - @asyncio.coroutine def get_bans(self, server): """|coro| @@ -1985,6 +1984,84 @@ class Client: data = yield from self.http.get_bans(server.id) return [User(**user['user']) for user in data] + @asyncio.coroutine + def prune_members(self, server, *, days): + """|coro| + + Prunes a :class:`Server` from its inactive members. + + The inactive members are denoted if they have not logged on in + ``days`` number of days and they have no roles. + + You must have the "Kick Members" permission to use this. + + To check how many members you would prune without actually pruning, + see the :meth:`estimate_pruned_members` function. + + Parameters + ----------- + server: :class:`Server` + The server to prune from. + days: int + The number of days before counting as inactive. + + Raises + ------- + Forbidden + You do not have permissions to prune members. + HTTPException + An error occurred while pruning members. + InvalidArgument + An integer was not passed for ``days``. + + Returns + --------- + int + The number of members pruned. + """ + + if not isinstance(days, int): + raise InvalidArgument('Expected int for ``days``, received {0.__class__.__name__} instead.'.format(days)) + + data = yield from self.http.prune_members(server.id, days) + return data['pruned'] + + @asyncio.coroutine + def estimate_pruned_members(self, server, *, days): + """|coro| + + Similar to :meth:`prune_members` except instead of actually + pruning members, it returns how many members it would prune + from the server had it been called. + + Parameters + ----------- + server: :class:`Server` + The server to estimate a prune from. + days: int + The number of days before counting as inactive. + + Raises + ------- + Forbidden + You do not have permissions to prune members. + HTTPException + An error occurred while fetching the prune members estimate. + InvalidArgument + An integer was not passed for ``days``. + + Returns + --------- + int + The number of members estimated to be pruned. + """ + + if not isinstance(days, int): + raise InvalidArgument('Expected int for ``days``, received {0.__class__.__name__} instead.'.format(days)) + + data = yield from self.http.estimate_pruned_members(server.id, days) + return data['pruned'] + # Invite management def _fill_invite_data(self, data): |