Added Warn and Ban Commands, Added Logging, and Much More

This commit is contained in:
Ahmad 2025-02-23 21:39:49 -05:00
parent d89de72e08
commit 86adac3f08
No known key found for this signature in database
GPG key ID: 8FD8A93530D182BF
33 changed files with 2200 additions and 204 deletions

View file

@ -0,0 +1,82 @@
import {
CommandInteraction,
PermissionsBitField,
SlashCommandBuilder,
SlashCommandOptionsOnlyBuilder,
} from 'discord.js';
import { executeUnban } from '../../util/helpers.js';
interface Command {
data: SlashCommandOptionsOnlyBuilder;
execute: (interaction: CommandInteraction) => Promise<void>;
}
const command: Command = {
data: new SlashCommandBuilder()
.setName('unban')
.setDescription('Unban a user from the server')
.addStringOption((option) =>
option
.setName('userid')
.setDescription('The Discord ID of the user to unban')
.setRequired(true),
)
.addStringOption((option) =>
option
.setName('reason')
.setDescription('The reason for the unban')
.setRequired(true),
),
execute: async (interaction) => {
const userId = interaction.options.get('userid')!.value as string;
const reason = interaction.options.get('reason')?.value as string;
if (
!interaction.memberPermissions?.has(PermissionsBitField.Flags.BanMembers)
) {
await interaction.reply({
content: 'You do not have permission to unban users.',
flags: ['Ephemeral'],
});
return;
}
try {
try {
const ban = await interaction.guild?.bans.fetch(userId);
if (!ban) {
await interaction.reply({
content: 'This user is not banned.',
flags: ['Ephemeral'],
});
return;
}
} catch {
await interaction.reply({
content: 'Error getting ban. Is this user banned?',
flags: ['Ephemeral'],
});
return;
}
await executeUnban(
interaction.client,
interaction.guildId!,
userId,
reason,
);
await interaction.reply({
content: `<@${userId}> has been unbanned. Reason: ${reason}`,
});
} catch (error) {
console.error(error);
await interaction.reply({
content: 'Unable to unban user.',
flags: ['Ephemeral'],
});
}
},
};
export default command;