Skip to content

Commit

Permalink
[Enhancement] Added embed message and a dondition to test if the user…
Browse files Browse the repository at this point in the history
… has permission before proceeding with the kick
  • Loading branch information
naseif committed Aug 30, 2021
1 parent 2753a5e commit 11aca2b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions commands/admin/kick.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const { SlashCommandBuilder } = require("@discordjs/builders");
const { Permissions } = require("discord.js");
const { embedMessage } = require("../../modules/embedSimple");

module.exports = {
data: new SlashCommandBuilder()
Expand All @@ -17,6 +18,10 @@ module.exports = {
await interaction.deferReply();

const embed = {
author: {
name: `${interaction.user.username}`,
icon_url: `${interaction.user.avatarURL()}`,
},
color: "#9dcc37",
title: `A user has been kicked!`,
fields: [
Expand All @@ -33,14 +38,26 @@ module.exports = {
timestamp: new Date(),
};

if (interaction.member.permissions.has([Permissions.FLAGS.KICK_MEMBERS])) {
try {
await interaction.guild.members.kick(user, { reason });
await interaction.followUp({ embeds: [embed] });
} catch (error) {
await interaction.followUp(`Couldn't kick ${user}, ${error.message}`);
console.log(error);
}
if (!interaction.member.permissions.has([Permissions.FLAGS.KICK_MEMBERS]))
return await interaction.followUp({
embeds: [
embedMessage(
"#9dcc37",
`❌ | You do not have permission to kick members!`
),
],
});

try {
await interaction.guild.members.kick(user, { reason });
await interaction.followUp({ embeds: [embed] });
} catch (error) {
await interaction.followUp({
embeds: [
embedMessage("#9dcc37", `Couldn't kick ${user}, ${error.message}`),
],
});
console.log(error);
}
},
};

0 comments on commit 11aca2b

Please sign in to comment.