Files
Papo/src/commands/admin/ban.ts

31 lines
1.2 KiB
TypeScript

import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction } from 'discord.js';
import { SlashCommand } from '../../utils/types';
import { context } from '../../config/context';
const command: SlashCommand = {
guildOnly: true,
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Bannt einen Nutzer.')
.addUserOption((opt) => opt.setName('user').setDescription('Nutzer').setRequired(true))
.addStringOption((opt) => opt.setName('reason').setDescription('Grund'))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers),
async execute(interaction: ChatInputCommandInteraction) {
const user = interaction.options.getUser('user', true);
const reason = interaction.options.getString('reason') ?? 'Kein Grund angegeben';
if (!interaction.guild) return;
const member = await interaction.guild.members.fetch(user.id).catch(() => null);
if (!member) {
await interaction.reply({ content: 'Mitglied nicht gefunden.', ephemeral: true });
return;
}
await member.ban({ reason }).catch(() => null);
await interaction.reply({ content: `${user.tag} wurde gebannt. Grund: ${reason}` });
context.logging.logAction(user, 'Ban', reason);
}
};
export default command;