mbot/commands/moderation/kick.js
2024-05-15 21:21:21 -07:00

40 lines
1.8 KiB
JavaScript

const { SlashCommandBuilder, PermissionsBitField } = require('discord.js');
const informationStatus = "[INFO]: ";
const warningStatus = "[WARNING]: ";
const errorStatus = "[ERROR]: ";
module.exports = {
data: new SlashCommandBuilder()
.setName('kick')
.setDescription('Kick a member from the server.')
.addUserOption(option =>
option.setName('user')
.setDescription('The member to kick')
.setRequired(true))
.addStringOption(option =>
option.setName('reason')
.setDescription('The reason for the kick')),
async execute(interaction){
const member = interaction.options.getMember('user');
const reason = interaction.options.getString('reason') ?? "No reason specified!";
if(!interaction.member.permissions.has(PermissionsBitField.Flags.KickMembers)) return interaction.reply({ content: "<:xmark:1238963594758979736> You dont have permission to use this command", ephemeral: true });
if(member.id == interaction.client.user.id) return interaction.reply({ content: "<:xmark:1238963594758979736> Cannot kick this bot via this command.", ephemeral: true});
if(member.id == interaction.member.id) return interaction.reply({ content: "<:xmark:1238963594758979736> Cannot kick the user summoning the command.", ephemeral: true });
try {
await member.kick({ reason: `${reason}` });
await interaction.reply(`<:checkmark:1238964552482422844> ${member} was kicked for the reason of ${reason}`);
console.log(informationStatus + `${member} was kicked due to ${reason}`);
} catch(error) {
await interaction.reply({ content: "Sorry! Could not execute the kick command. Something went wrong", ephemeral: true });
console.log(errorStatus + "Something went wrong while trying to kick a member! Debug information is below.");
console.error(error);
}
}
}