mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-09-07 10:22:59 +00:00
Add support for bulk banning members
This commit is contained in:
@ -34,6 +34,7 @@ from typing import (
|
||||
Collection,
|
||||
Coroutine,
|
||||
Dict,
|
||||
Iterable,
|
||||
List,
|
||||
Mapping,
|
||||
NamedTuple,
|
||||
@ -146,6 +147,11 @@ class BanEntry(NamedTuple):
|
||||
user: User
|
||||
|
||||
|
||||
class BulkBanResult(NamedTuple):
|
||||
banned: List[Object]
|
||||
failed: List[Object]
|
||||
|
||||
|
||||
class _GuildLimit(NamedTuple):
|
||||
emoji: int
|
||||
stickers: int
|
||||
@ -3789,6 +3795,58 @@ class Guild(Hashable):
|
||||
"""
|
||||
await self._state.http.unban(user.id, self.id, reason=reason)
|
||||
|
||||
async def bulk_ban(
|
||||
self,
|
||||
users: Iterable[Snowflake],
|
||||
*,
|
||||
reason: Optional[str] = None,
|
||||
delete_message_seconds: int = 86400,
|
||||
) -> BulkBanResult:
|
||||
"""|coro|
|
||||
|
||||
Bans multiple users from the guild.
|
||||
|
||||
The users must meet the :class:`abc.Snowflake` abc.
|
||||
|
||||
You must have :attr:`~Permissions.ban_members` to do this.
|
||||
|
||||
.. versionadded:: 2.4
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
users: :class:`abc.Snowflake`
|
||||
The user to ban from their guild.
|
||||
delete_message_seconds: :class:`int`
|
||||
The number of seconds worth of messages to delete from the user
|
||||
in the guild. The minimum is 0 and the maximum is 604800 (7 days).
|
||||
Defaults to 1 day.
|
||||
reason: Optional[:class:`str`]
|
||||
The reason the users got banned.
|
||||
|
||||
Raises
|
||||
-------
|
||||
Forbidden
|
||||
You do not have the proper permissions to ban.
|
||||
HTTPException
|
||||
Banning failed.
|
||||
|
||||
Returns
|
||||
--------
|
||||
:class:`BulkBanResult`
|
||||
The result of the bulk ban operation.
|
||||
"""
|
||||
|
||||
response = await self._state.http.bulk_ban(
|
||||
self.id,
|
||||
user_ids=[u.id for u in users],
|
||||
delete_message_seconds=delete_message_seconds,
|
||||
reason=reason,
|
||||
)
|
||||
return BulkBanResult(
|
||||
banned=[Object(id=int(user_id), type=User) for user_id in response.get('banned_users', []) or []],
|
||||
failed=[Object(id=int(user_id), type=User) for user_id in response.get('failed_users', []) or []],
|
||||
)
|
||||
|
||||
@property
|
||||
def vanity_url(self) -> Optional[str]:
|
||||
"""Optional[:class:`str`]: The Discord vanity invite URL for this guild, if available.
|
||||
|
Reference in New Issue
Block a user