40 lines
1.8 KiB
JavaScript
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('ban')
|
||
|
.setDescription('Ban a member from the server.')
|
||
|
.addUserOption(option =>
|
||
|
option.setName('user')
|
||
|
.setDescription('The member to ban')
|
||
|
.setRequired(true))
|
||
|
.addStringOption(option=>
|
||
|
option.setName('reason')
|
||
|
.setDescription('The reason for ban')),
|
||
|
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.BanMembers)) 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 ban this bot via this command.", ephemeral: true});
|
||
|
|
||
|
if(member.id == interaction.member.id) return interaction.reply({ content: "<:xmark:1238963594758979736> Cannot ban the user summoning the command.", ephemeral: true });
|
||
|
|
||
|
try {
|
||
|
await member.ban({ reason: `${reason}` });
|
||
|
await interaction.reply(`<:checkmark:1238964552482422844> ${member} was banned for the reason of ${reason}`);
|
||
|
|
||
|
console.log(informationStatus + `${member} was banned due to ${reason}`);
|
||
|
} catch(error) {
|
||
|
await interaction.reply({ content: "Sorry! Could not execute the ban command. Something went wrong", ephemeral: true });
|
||
|
console.log(errorStatus + "Something went wrong while trying to ban a member! Debug information is below.");
|
||
|
console.error(error);
|
||
|
}
|
||
|
}
|
||
|
}
|