@@ -199,6 +199,51 @@ class GuildBanManager extends CachedManager {
199
199
await this . client . rest . delete ( Routes . guildBan ( this . guild . id , id ) , { reason } ) ;
200
200
return this . client . users . resolve ( user ) ;
201
201
}
202
+
203
+ /**
204
+ * Options used for bulk banning users from a guild.
205
+ * @typedef {Object } BulkBanOptions
206
+ * @property {number } [deleteMessageSeconds] Number of seconds of messages to delete,
207
+ * must be between 0 and 604800 (7 days), inclusive
208
+ * @property {string } [reason] The reason for the bans
209
+ */
210
+
211
+ /**
212
+ * Result of bulk banning users from a guild.
213
+ * @typedef {Object } BulkBanResult
214
+ * @property {Snowflake[] } bannedUsers IDs of the banned users
215
+ * @property {Snowflake[] } failedUsers IDs of the users that could not be banned or were already banned
216
+ */
217
+
218
+ /**
219
+ * Bulk ban users from a guild, and optionally delete previous messages sent by them.
220
+ * @param {Collection<Snowflake, UserResolvable>|UserResolvable[] } users The users to ban
221
+ * @param {BulkBanOptions } [options] The options for bulk banning users
222
+ * @returns {Promise<BulkBanResult> } Returns an object with `bannedUsers` key containing the IDs of the banned users
223
+ * and the key `failedUsers` with the IDs that could not be banned or were already banned.
224
+ * @example
225
+ * // Bulk ban users by ids (or with user/guild member objects) and delete all their messages from the past 7 days
226
+ * guild.bans.bulkCreate(['84484653687267328'], { deleteMessageSeconds: 7 * 24 * 60 * 60 })
227
+ * .then(result => {
228
+ * console.log(`Banned ${result.bannedUsers.length} users, failed to ban ${result.failedUsers.length} users.`)
229
+ * })
230
+ * .catch(console.error);
231
+ */
232
+ async bulkCreate ( users , options = { } ) {
233
+ if ( ! users || ! ( Array . isArray ( users ) || users instanceof Collection ) ) {
234
+ throw new DiscordjsTypeError ( ErrorCodes . InvalidType , 'users' , 'Array or Collection of UserResolvable' , true ) ;
235
+ }
236
+ if ( typeof options !== 'object' ) throw new DiscordjsTypeError ( ErrorCodes . InvalidType , 'options' , 'object' , true ) ;
237
+
238
+ const userIds = users . map ( user => this . client . users . resolveId ( user ) ) ;
239
+ if ( userIds . length === 0 ) throw new DiscordjsError ( ErrorCodes . BulkBanUsersOptionEmpty ) ;
240
+
241
+ const result = await this . client . rest . post ( Routes . guildBulkBan ( this . guild . id ) , {
242
+ body : { delete_message_seconds : options . deleteMessageSeconds , user_ids : userIds } ,
243
+ reason : options . reason ,
244
+ } ) ;
245
+ return { bannedUsers : result . banned_users , failedUsers : result . failed_users } ;
246
+ }
202
247
}
203
248
204
249
module . exports = GuildBanManager ;
0 commit comments