Skip to content

Commit

Permalink
feat: support bulk-banning members
Browse files Browse the repository at this point in the history
  • Loading branch information
TTtie committed Apr 2, 2024
1 parent bbf3a8b commit 01cd07c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 0 deletions.
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -888,6 +888,10 @@ declare namespace Dysnomia {
deleteMessageSeconds?: number;
reason?: string;
}
interface BulkGuildMemberBanResult {
bannedUsers: string[];
failedUsers: string[];
}
interface CreateGuildOptions {
afkChannelID?: string;
afkTimeout?: number;
Expand Down Expand Up @@ -2572,6 +2576,7 @@ declare namespace Dysnomia {
addGuildMemberRole(guildID: string, memberID: string, roleID: string, reason?: string): Promise<void>;
addMessageReaction(channelID: string, messageID: string, reaction: string): Promise<void>;
banGuildMember(guildID: string, userID: string, options?: BanMemberOptions): Promise<void>;
bulkBanGuildMembers(guildID: string, userIDs: string[], options?: BanMemberOptions): Promise<BulkGuildMemberBanResult>;
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<AnyApplicationCommand<true>[]>;
bulkEditGuildCommands(guildID: string, commands: ApplicationCommandStructure[]): Promise<AnyApplicationCommand<true>[]>;
closeVoiceConnection(guildID: string): void;
Expand Down Expand Up @@ -2999,6 +3004,7 @@ declare namespace Dysnomia {
addMember(userID: string, accessToken: string, options?: AddGuildMemberOptions): Promise<void>;
addMemberRole(memberID: string, roleID: string, reason?: string): Promise<void>;
banMember(userID: string, options?: BanMemberOptions): Promise<void>;
bulkBanMembers(guildID: string, userIDs: string[], options?: BanMemberOptions): Promise<BulkGuildMemberBanResult>;
bulkEditCommands(commands: ApplicationCommandStructure[]): Promise<AnyApplicationCommand[]>;
createAutoModerationRule(rule: CreateAutoModerationRuleOptions): Promise<AutoModerationRule>;
createChannel(name: string): Promise<TextChannel>;
Expand Down
19 changes: 19 additions & 0 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,25 @@ class Client extends EventEmitter {
});
}

/**
* Ban multiple users from a guild
* @arg {String} guildID The ID of the guild
* @arg {Array<String>} userIDs A list of user IDs to ban
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<{ bannedUsers: Array<String>, failedUsers: Array<String> }>}
*/
bulkBanGuildMembers(guildID, userIDs, options) {
return this.requestHandler.request("POST", Endpoints.GUILD_BULK_BAN(guildID), true, {
user_ids: userIDs,
delete_message_seconds: options.deleteMessageSeconds || 0,
reason: options.reason
}).then((result) => ({
bannedUsers: result.banned_users,
failedUsers: result.failed_users
}));
}

/**
* Edits command permissions for a multiple commands in a guild.
* Note: You can only add up to 10 permission overwrites for a command.
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ module.exports.GUILD = (guildID)
module.exports.GUILD_AUDIT_LOGS = (guildID) => `/guilds/${guildID}/audit-logs`;
module.exports.GUILD_BAN = (guildID, memberID) => `/guilds/${guildID}/bans/${memberID}`;
module.exports.GUILD_BANS = (guildID) => `/guilds/${guildID}/bans`;
module.exports.GUILD_BULK_BAN = (guildID) => `/guilds/${guildID}/bulk-ban`;
module.exports.GUILD_CHANNELS = (guildID) => `/guilds/${guildID}/channels`;
module.exports.GUILD_COMMAND = (applicationID, guildID, commandID) => `/applications/${applicationID}/guilds/${guildID}/commands/${commandID}`;
module.exports.GUILD_COMMAND_PERMISSIONS = (applicationID, guildID) => `/applications/${applicationID}/guilds/${guildID}/commands/permissions`;
Expand Down
12 changes: 12 additions & 0 deletions lib/structures/Guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,18 @@ class Guild extends Base {
return this.#client.banGuildMember.call(this.#client, this.id, userID, options);
}

/**
* Ban multiple users from the guild
* @arg {String} guildID The ID of the guild
* @arg {Array<String>} userIDs A list of user IDs to ban
* @arg {Number} [options.deleteMessageSeconds=0] Number of seconds to delete messages for, between 0 and 604800 inclusive
* @arg {String} [options.reason] The reason to be displayed in audit logs
* @returns {Promise<{ bannedUsers: Array<String>, failedUsers: Array<String> }>}
*/
bulkBanMembers(userIDs, options) {
return this.#client.bulkBanGuildMembers.call(this.#client, this.id, userIDs, options);
}

/**
* Edits command permissions for a multiple commands in a guild.
* Note: You can only add up to 10 permission overwrites for a command.
Expand Down

0 comments on commit 01cd07c

Please sign in to comment.