Repository: discordjs/discord.js
File: packages/discord.js/src/managers/GuildBanManager.js (JavaScript)

Code before:
   * Unbans a user from the guild.
   * @param {UserResolvable} user The user to unban
   * @param {string} [reason] Reason for unbanning user
   * @returns {Promise<?User>}
   * @example
   * // Unban a user by id (or with a user/guild member object)
   * guild.bans.remove('84484653687267328')
   *   .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
   *   .catch(console.error);
   */
  async remove(user, reason) {
    const id = this.client.users.resolveId(user);
    if (!id) throw new DiscordjsError(ErrorCodes.BanResolveId);
    await this.client.rest.delete(Routes.guildBan(this.guild.id, id), { reason });
    return this.client.users.resolve(user);
  }

  /**
   * Ban up to 200 users from a guild, and optionally delete previous messages sent by the banned users. Requires
   * both the `BAN_MEMBERS` and `MANAGE_GUILD` permissions.
   * @param {BanBulkOptions} options The options for bulk banning users
   * @returns {Promise<BanBulkResult>} Returns an object with `bannedUsers` key containing the IDs of the banned users
   * and the key `failedUsers` with the IDs that could not be banned or were already banned.
   * @example
   * // Bulk ban users
   * guild.bans.bulk({ users: ['84484653687267328'], deleteMessageSeconds: 604_800 })
   *   .then(result => console.log(`Banned ${result.bannedUsers.length} users, failed to ban ${result.failedUsers.length} users.`))
   *   .catch(console.error);
   */
  async bulk(options) {
    if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);
    if (!Object.hasOwn(options, 'users')) throw new Error('Object "options" has no "users" attribute');
    
    const { users } = options;

    if (!Array.isArray(users) && !(users instanceof Collection)) {
      throw new Error('Option "users" is not an array or collection');
    }
    
    let userIds = users instanceof Collection ? [...users.keys()] : users.map(user => user.id ?? user);
    if (userIds.length === 0) throw new Error('Option "users" array or collection is empty');
    const result = await this.client.rest.post(Routes.guildBulkBan(this.guild.id), {
      body: { user_ids: userIds, delete_message_seconds: options.deleteMessageSeconds ?? undefined },
    });
    return { bannedUsers: result.banned_users, failedUsers: result.failed_users };
  }
}

module.exports = GuildBanManager;


Review comment (suggestion):
```suggestion
   * guild.bans.bulk({ users: ['84484653687267328'], deleteMessageSeconds: 24 * 60 * 60 })
```

Much better as you can see

Code after:
   * Unbans a user from the guild.
   * @param {UserResolvable} user The user to unban
   * @param {string} [reason] Reason for unbanning user
   * @returns {Promise<?User>}
   * @example
   * // Unban a user by id (or with a user/guild member object)
   * guild.bans.remove('84484653687267328')
   *   .then(user => console.log(`Unbanned ${user.username} from ${guild.name}`))
   *   .catch(console.error);
   */
  async remove(user, reason) {
    const id = this.client.users.resolveId(user);
    if (!id) throw new DiscordjsError(ErrorCodes.BanResolveId);
    await this.client.rest.delete(Routes.guildBan(this.guild.id, id), { reason });
    return this.client.users.resolve(user);
  }

  /**
   * Options used for bulk banning users from a guild.
   * @typedef {Object} BulkBanOptions
   * @property {number} [deleteMessageSeconds] Number of seconds of messages to delete,
   * must be between 0 and 604800 (7 days), inclusive
   * @property {string} [reason] The reason for the bans
   */

  /**
   * Result of bulk banning users from a guild.
   * @typedef {Object} BulkBanResult
   * @property {Snowflake[]} bannedUsers IDs of the banned users
   * @property {Snowflake[]} failedUsers IDs of the users that could not be banned or were already banned
   */

  /**
   * Bulk ban users from a guild, and optionally delete previous messages sent by them.
   * @param {Collection<Snowflake, UserResolvable>|UserResolvable[]} users The users to ban
   * @param {BulkBanOptions} [options] The options for bulk banning users
   * @returns {Promise<BulkBanResult>} Returns an object with `bannedUsers` key containing the IDs of the banned users
   * and the key `failedUsers` with the IDs that could not be banned or were already banned.
   * @example
   * // Bulk ban users by ids (or with user/guild member objects) and delete all their messages from the past 7 days
   * guild.bans.bulkCreate(['84484653687267328'], { deleteMessageSeconds: 7 * 24 * 60 * 60 })
   *   .then(result => {
   *     console.log(`Banned ${result.bannedUsers.length} users, failed to ban ${result.failedUsers.length} users.`)
   *   })
   *   .catch(console.error);
   */
  async bulkCreate(users, options = {}) {
    if (!users || !(Array.isArray(users) || users instanceof Collection)) {
      throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'users', 'Array or Collection of UserResolvable', true);
    }
    if (typeof options !== 'object') throw new DiscordjsTypeError(ErrorCodes.InvalidType, 'options', 'object', true);