Skip to content

Commit

Permalink
feat: Support bulk banning (#1541)
Browse files Browse the repository at this point in the history
  • Loading branch information
conorwastakenwastaken authored Sep 22, 2024
1 parent c3e3a31 commit 577afc8
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
9 changes: 9 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,13 @@ declare namespace Eris {
deleteMessageSeconds?: number;
reason?: string;
}
interface BulkBanMembersOptions extends Omit<BanMemberOptions, "deleteMessageDays"> {
userIDs: string[];
}
interface BulkBanMembersResponse {
banned_users: string[];
failed_users: string[];
}
interface CreateGuildOptions {
afkChannelID?: string;
afkTimeout?: number;
Expand Down Expand Up @@ -2055,6 +2062,7 @@ declare namespace Eris {
banGuildMember(guildID: string, userID: string, options?: BanMemberOptions): Promise<void>;
/** @deprecated */
banGuildMember(guildID: string, userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
bulkBanGuildMembers(guildID: string, options: BulkBanMembersOptions): Promise<BulkBanMembersResponse>;
bulkEditCommands(commands: ApplicationCommandBulkEditOptions<false>[]): Promise<ApplicationCommand<false>[]>;
bulkEditGuildCommands(guildID: string, commands: ApplicationCommandBulkEditOptions<true>[]): Promise<ApplicationCommand<true>[]>;
closeVoiceConnection(guildID: string): void;
Expand Down Expand Up @@ -2530,6 +2538,7 @@ declare namespace Eris {
banMember(userID: string, options?: BanMemberOptions): Promise<void>;
/** @deprecated */
banMember(userID: string, deleteMessageDays?: number, reason?: string): Promise<void>;
bulkBanMembers(options: BulkBanMembersOptions): Promise<BulkBanMembersResponse>;
bulkEditCommands<T extends ApplicationCommandTypes>(commands: ApplicationCommandBulkEditOptions<true, T>[]): Promise<ApplicationCommand<true, T>[]>;
createAutoModerationRule(rule: CreateAutoModerationRuleOptions): Promise<AutoModerationRule>;
createChannel(name: string): Promise<TextChannel>;
Expand Down
17 changes: 17 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,23 @@ class Client extends EventEmitter {
});
}

/**
* Bulk ban users from a guild - Note: Requires both BAN_MEMBERS and MANAGE_GUILD permissions
* @arg {String} guildID The ID of the guild
* @arg {Object} options Options for banning the users
* @arg {Array<String>} options.userIDs Array of user IDs to ban
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for each user, between 0 and 604800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<Object>} An object with 2 arrays - `banned_users` with the IDs of the successfully banned users, and `failed_users` with the IDs of any users who could not be banned or were already banned
*/
bulkBanGuildMembers(guildID, options) {
return this.requestHandler.request("POST", Endpoints.GUILD_BULK_BAN(guildID), true, {
user_ids: options.userIDs,
delete_message_seconds: options.deleteMessageSeconds || 0,
reason: options.reason
})
}

/**
* Bulk create/edit global application commands
* @arg {Array<Object>} commands An array of command objects
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,18 @@ class Guild extends Base {
return this._client.banGuildMember.call(this._client, this.id, userID, options, reason);
}

/**
* Bulk ban users from the guild - Note: Requires both BAN_MEMBERS and MANAGE_GUILD permissions
* @arg {Object} options Options for banning the users
* @arg {Array<String>} options.userIDs Array of user IDs to ban
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for each user, between 0 and 604800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<Object>} An object with 2 arrays - `banned_users` with the IDs of the successfully banned users, and `failed_users` with the IDs of any users who could not be banned or were already banned
*/
bulkBanMembers(options) {
return this._client.bulkBanGuildMembers.call(this._client, this.id, options);
}

/**
* Bulk create/edit the guild application commands
* @arg {Array<Object>} commands An array of command objects
Expand Down

0 comments on commit 577afc8

Please sign in to comment.