Please look over - not for production
diff --git a/src/commands/mod/ban.ts b/src/commands/mod/ban.ts
index 628b607..88f7b39 100644
--- a/src/commands/mod/ban.ts
+++ b/src/commands/mod/ban.ts
@@ -3,9 +3,9 @@
GuildMember,
ActionRowBuilder,
ButtonBuilder,
- User,
ButtonStyle,
- SlashCommandSubcommandBuilder
+ SlashCommandSubcommandBuilder,
+ ButtonInteraction
} from "discord.js";
import confirmationMessage from "../../utils/confirmationMessage.js";
import EmojiEmbed from "../../utils/generateEmojiEmbed.js";
@@ -29,8 +29,16 @@
.setRequired(false)
);
-const callback = async (interaction: CommandInteraction): Promise<void> => {
+const callback = async (interaction: CommandInteraction | ButtonInteraction, member?: GuildMember): Promise<void> => {
if (!interaction.guild) return;
+ let deleteDays;
+ if (!interaction.isButton()) {
+ member = interaction.options.getMember("user") as GuildMember;
+ deleteDays = (interaction.options.get("delete")?.value as number | null) ?? 0
+ } else {
+ deleteDays = 0;
+ }
+ if (!member) return;
const { renderUser } = client.logger;
// TODO:[Modals] Replace the command arguments with a modal
let reason = null;
@@ -44,15 +52,12 @@
.setTitle("Ban")
.setDescription(
keyValueList({
- user: renderUser(interaction.options.getUser("user")!),
+ user: renderUser(member.user),
reason: reason ? "\n> " + reason.replaceAll("\n", "\n> ") : "*No reason provided*"
}) +
`The user **will${notify ? "" : " not"}** be notified\n` +
- `${addPlurals(
- (interaction.options.get("delete")?.value as number | null) ?? 0,
- "day"
- )} of messages will be deleted\n\n` +
- `Are you sure you want to ban <@!${(interaction.options.getMember("user") as GuildMember).id}>?`
+ `${addPlurals(deleteDays, "day")} of messages will be deleted\n\n` +
+ `Are you sure you want to ban <@!${member.id}>?`
)
.addCustomBoolean(
"notify",
@@ -113,23 +118,21 @@
.setURL(
config.moderation.ban.link.replaceAll(
"{id}",
- (interaction.options.getMember("user") as GuildMember).id
+ member.id
)
)
)
);
}
- dmMessage = await (interaction.options.getMember("user") as GuildMember).send(messageData);
+ dmMessage = await member.send(messageData);
dmSent = true;
}
} catch {
dmSent = false;
}
try {
- const member = interaction.options.getMember("user") as GuildMember;
- const days: number = (interaction.options.get("delete")?.value as number | null) ?? 0;
member.ban({
- deleteMessageSeconds: days * 24 * 60 * 60,
+ deleteMessageSeconds: deleteDays * 24 * 60 * 60,
reason: reason ?? "*No reason provided*"
});
await client.database.history.create("ban", interaction.guild.id, member.user, interaction.user, reason);
@@ -189,23 +192,22 @@
});
};
-const check = async (interaction: CommandInteraction, partial: boolean = false) => {
+const check = (interaction: CommandInteraction | ButtonInteraction, partial: boolean = false, target?: GuildMember) => {
if (!interaction.guild) return;
const member = interaction.member as GuildMember;
// Check if the user has ban_members permission
if (!member.permissions.has("BanMembers")) return "You do not have the *Ban Members* permission";
if (partial) return true;
const me = interaction.guild.members.me!;
- let apply = interaction.options.getUser("user") as User | GuildMember;
+ let apply: GuildMember;
+ if (interaction.isButton()) {
+ apply = target!;
+ } else {
+ apply = interaction.options.getMember("user") as GuildMember;
+ };
const memberPos = member.roles.cache.size > 1 ? member.roles.highest.position : 0;
const mePos = me.roles.cache.size > 1 ? me.roles.highest.position : 0;
- let applyPos = 0;
- try {
- apply = (await interaction.guild.members.fetch(apply.id)) as GuildMember;
- applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
- } catch {
- apply = apply as User;
- }
+ const applyPos = apply.roles.cache.size > 1 ? apply.roles.highest.position : 0;
// Do not allow banning the owner
if (member.id === interaction.guild.ownerId) return "You cannot ban the owner of the server";
// Check if Nucleus can ban the member