Skip to content

Commit

Permalink
[Enhancement] Added embed message for the catch block and a condition…
Browse files Browse the repository at this point in the history
… to check if the user can ban members
  • Loading branch information
naseif committed Aug 30, 2021
1 parent 11aca2b commit 6aa0094
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions commands/admin/ban.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 Banned!`,
fields: [
Expand All @@ -33,14 +38,26 @@ module.exports = {
timestamp: new Date(),
};

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

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

0 comments on commit 6aa0094

Please sign in to comment.