32
32
Any ,
33
33
ClassVar ,
34
34
List ,
35
- Literal ,
36
35
NamedTuple ,
37
36
Optional ,
38
37
Sequence ,
@@ -3076,7 +3075,6 @@ async def ban(
3076
3075
user : Snowflake ,
3077
3076
* ,
3078
3077
delete_message_seconds : int | None = None ,
3079
- delete_message_days : Literal [0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 ] | None = None ,
3080
3078
reason : str | None = None ,
3081
3079
) -> None :
3082
3080
"""|coro|
@@ -3096,9 +3094,6 @@ async def ban(
3096
3094
The number of seconds worth of messages to delete from
3097
3095
the user in the guild. The minimum is 0 and the maximum
3098
3096
is 604800 (i.e. 7 days). The default is 0.
3099
- delete_message_days: Optional[:class:`int`]
3100
- ***Deprecated parameter***, same as ``delete_message_seconds`` but
3101
- is used for days instead.
3102
3097
reason: Optional[:class:`str`]
3103
3098
The reason the user got banned.
3104
3099
@@ -3109,21 +3104,88 @@ async def ban(
3109
3104
HTTPException
3110
3105
Banning failed.
3111
3106
"""
3112
- if delete_message_seconds and delete_message_days :
3107
+
3108
+ if delete_message_seconds is not None and not (
3109
+ 0 <= delete_message_seconds <= 604800
3110
+ ):
3113
3111
raise TypeError (
3114
- "delete_message_seconds and delete_message_days are mutually exclusive ."
3112
+ "delete_message_seconds must be between 0 and 604800 seconds ."
3115
3113
)
3116
3114
3115
+ await self ._state .http .ban (
3116
+ user .id , self .id , delete_message_seconds , reason = reason
3117
+ )
3118
+
3119
+ async def bulk_ban (
3120
+ self ,
3121
+ * users : Snowflake ,
3122
+ delete_message_seconds : int | None = None ,
3123
+ reason : str | None = None ,
3124
+ ) -> list [list [Snowflake ], list [Snowflake ]]:
3125
+ r"""|coro|
3126
+
3127
+ Bulk ban users from the guild.
3128
+
3129
+ The users must meet the :class:`abc.Snowflake` abc.
3130
+
3131
+ You must have the :attr:`~Permissions.ban_members` permission to
3132
+ do this.
3133
+
3134
+ Example Usage: ::
3135
+
3136
+ # Ban multiple users
3137
+ successes, failures = await guild.ban(user1, user2, user3, ..., reason="Raid")
3138
+
3139
+ # Ban a list of users
3140
+ successes, failures = await guild.ban(*users)
3141
+
3142
+ Parameters
3143
+ ----------
3144
+ \*users: :class:`abc.Snowflake`
3145
+ An argument list of users to ban from the guild, up to 200.
3146
+ delete_message_seconds: Optional[:class:`int`]
3147
+ The number of seconds worth of messages to delete from
3148
+ the user in the guild. The minimum is 0 and the maximum
3149
+ is 604800 (i.e. 7 days). The default is 0.
3150
+ reason: Optional[:class:`str`]
3151
+ The reason the users were banned.
3152
+
3153
+ Returns
3154
+ -------
3155
+ List[List[:class:`abc.Snowflake`], List[:class:`abc.Snowflake`]]
3156
+ Returns two lists: the first contains members that were successfully banned, while the second is members that could not be banned.
3157
+
3158
+ Raises
3159
+ ------
3160
+ ValueError
3161
+ You tried to ban more than 200 users.
3162
+ Forbidden
3163
+ You do not have the proper permissions to ban.
3164
+ HTTPException
3165
+ No users were banned.
3166
+ """
3167
+
3117
3168
if delete_message_seconds is not None and not (
3118
3169
0 <= delete_message_seconds <= 604800
3119
3170
):
3120
3171
raise TypeError (
3121
3172
"delete_message_seconds must be between 0 and 604800 seconds."
3122
3173
)
3123
3174
3124
- await self ._state .http .ban (
3125
- user .id , self .id , delete_message_seconds , delete_message_days , reason = reason
3175
+ if len (users ) > 200 or len (users ) < 1 :
3176
+ raise ValueError (
3177
+ "The number of users to be banned must be between 1 and 200."
3178
+ )
3179
+
3180
+ data = await self ._state .http .bulk_ban (
3181
+ [u .id for u in users ],
3182
+ self .id ,
3183
+ delete_message_seconds ,
3184
+ reason = reason ,
3126
3185
)
3186
+ banned = [u for u in users if str (u .id ) in data ["banned_users" ]]
3187
+ failed = [u for u in users if str (u .id ) in data ["failed_users" ]]
3188
+ return banned , failed
3127
3189
3128
3190
async def unban (self , user : Snowflake , * , reason : str | None = None ) -> None :
3129
3191
"""|coro|
0 commit comments