2025-02-02 14:10:51 -05:00
|
|
|
// kick.js - Discord bot kick command
|
|
|
|
|
// Copyright (C) 2025 Luis Bauza
|
|
|
|
|
//
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
2025-02-09 14:58:31 -05:00
|
|
|
import { SlashCommandBuilder, PermissionFlagsBits } from 'discord.js';
|
2025-03-25 11:17:26 -04:00
|
|
|
import Command from '../utils/Command.js';
|
2025-02-02 14:10:51 -05:00
|
|
|
|
2025-03-25 11:17:26 -04:00
|
|
|
export default class KickCommand extends Command {
|
|
|
|
|
defineCommand() {
|
|
|
|
|
return new SlashCommandBuilder()
|
|
|
|
|
.setName('kick')
|
|
|
|
|
.setDescription('Kick a user from the server')
|
|
|
|
|
.addUserOption(option =>
|
|
|
|
|
option.setName('target').setDescription('The user to kick').setRequired(true),
|
|
|
|
|
)
|
|
|
|
|
.addStringOption(option => option.setName('reason').setDescription('Reason for kicking'))
|
|
|
|
|
.setDefaultMemberPermissions(PermissionFlagsBits.KickMembers);
|
|
|
|
|
}
|
2025-02-09 14:58:31 -05:00
|
|
|
|
2025-03-25 11:17:26 -04:00
|
|
|
async run(interaction) {
|
2025-02-02 14:10:51 -05:00
|
|
|
const target = interaction.options.getMember('target');
|
2025-02-09 14:58:31 -05:00
|
|
|
const reason = interaction.options.getString('reason') ?? 'No reason provided';
|
2025-02-02 14:10:51 -05:00
|
|
|
|
|
|
|
|
if (!target) {
|
2025-03-25 11:17:26 -04:00
|
|
|
throw new Error('That user is not in this server!');
|
2025-02-02 14:10:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!target.kickable) {
|
2025-03-25 11:17:26 -04:00
|
|
|
throw new Error('I cannot kick this user! They may have higher permissions than me.');
|
2025-02-02 14:10:51 -05:00
|
|
|
}
|
|
|
|
|
|
2025-03-25 11:17:26 -04:00
|
|
|
await target.kick(reason);
|
|
|
|
|
await interaction.reply({
|
|
|
|
|
content: `Successfully kicked ${target.user.tag}\nReason: ${reason}`,
|
|
|
|
|
ephemeral: true,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|