const { Discord, MessageEmbed } = require("discord.js");
module.exports = {
name: "ban",
description: "bans user from guild",
execute(client, message, cmd, args, Discord) {
const member = message.mentions.users.first();
const user = message.mentions.members.first();
let admin = message.author.username;
let server = message.guild.name;
const memberTarget = message.guild.members.cache.get(member.id);
let reason = args.join(" ").slice(22);
if (!reason) reason = "No reason provided";
const embed = new MessageEmbed().setDescription("`Please remember to mention the user **(Members, UserID)**`").setColor("YELLOW");
const embed1 = new MessageEmbed().setDescription("You dont have enough permissions to execute this command!").setColor("RED");
const embed2 = new MessageEmbed().setDescription("`Sorry But this User is not Bannable`").setColor("RED");
const embed4 = new MessageEmbed().setTitle(`You have been banned from ${server}!`).setThumbnail(`${message.guild.iconURL()}`).addField("Reason:", `${reason}`).setFooter(`you were banned by ${admin}`).setTimestamp().setColor("RED");
const embed5 = new MessageEmbed().setDescription(`**${admin}**, You Cannot Ban Yourself`);
if (user.id === message.author.id) {
message.channel.send({ embeds: [embed5] });
}
if (
message.member.roles.cache.some((role) => role.name === "Administrator") ||
message.member.roles.cache.some((role) => role.name === "Admin") ||
message.member.roles.cache.some((role) => role.name === "Moderator") ||
message.member.roles.cache.some((role) => role.name === "Mod")
) {
message.channel.send(`Sorry I cannot ban Admins/Mods`);
} else {
if (!message.mentions.users.first()) return message.channel.send({ embeds: [embed] });
if (!message.member.permissions.has("KICK_MEMBERS")) return message.channel.send({ embeds: [embed1] });
if (!user.kickable) return message.channel.send({ embeds: [embed2] });
if (!!message.mentions.users.first() && message.member.permissions.has("KICK_MEMBERS")) {
const embed3 = new MessageEmbed()
.setColor("BLACK")
.setThumbnail(message.mentions.users.first().displayAvatarURL())
.setDescription(`<@${memberTarget.user.id}> has been banned!`)
.addField("Reason", `${reason}`)
.setFooter(`Banned by ${admin}`)
.setTimestamp();
user.send({ embeds: [embed4] });
setTimeout(function () {
user.ban()
.catch((err) => console.log(err))
.then(() => {
message.channel.send({ embeds: [embed3] });
message.channel.bulkDelete(1);
}, 20000);
});
}
}
},
};
So I'm seeking a way to get my bot not to ban Admin or Mod roles, however, the current way I have it set up it believes every member has said roles.
I'm looking to see if there is a better way to seek roles or if I have to move stuff around.
Help would really be appreciated as I'm trying my hardest to get this patched ASAP. Thanks in advance!
CodePudding user response:
You are missing an else
between
if(user.id === message.author.id){
message.channel.send({ embeds: [embed5] })
}
and
if (message.member
One way to make things like this more obvious is to auto-format your code.
CodePudding user response:
const { Discord, MessageEmbed } = require("discord.js")
module.exports = {
name: 'ban',
description: "bans user from guild",
execute(client, message, cmd, args, Discord){
const member = message.mentions.users.first();
const user = message.mentions.members.first();
let admin = message.author.username;
let server = message.guild.name;
let reason = args.join(" ").slice(22);
if(!reason) reason = "No reason provided";
const embed = new MessageEmbed()
.setDescription("`Please remember to mention the user **(Members, UserID)**`")
.setColor("YELLOW")
const embed1 = new MessageEmbed()
.setDescription("You dont have enough permissions to execute this command!")
.setColor("RED")
const embed2 = new MessageEmbed()
.setDescription("`Sorry But this User is not Bannable`")
.setColor("RED")
const embed4 = new MessageEmbed()
.setTitle(`You have been banned from ${server}!`)
.setThumbnail(`${message.guild.iconURL()}`)
.addField('Reason:', `${reason}`)
.setFooter(`you were banned by ${admin}`)
.setTimestamp()
.setColor('RED')
const embed5 = new MessageEmbed()
.setDescription(`**${admin}**, You Cannot Ban Yourself`)
if(!message.member.permissions.has('KICK_MEMBERS')) return message.channel.send({ embeds: [embed1] })
if(!message.mentions.users.first()) return message.channel.send({ embeds: [embed] })
if(user.id === message.author.id){
message.channel.send({ embeds: [embed5] })
} else if (user.roles.cache.some(role => ['Administrator', 'Admin', 'Moderator', 'Mod'].includes(role.name))){
message.channel.send(`Sorry I cannot ban Admins/Mods`)
} else {
if(!user.kickable) return message.channel.send({ embeds: [embed2] })
if(!!message.mentions.users.first() && message.member.permissions.has('BAN_MEMBERS')) {
const memberTarget = message.guild.members.cache.get(member.id)
const embed3 = new MessageEmbed()
.setColor("BLACK")
.setThumbnail(message.mentions.users.first().displayAvatarURL())
.setDescription(`<@${memberTarget.user.id}> has been banned!`)
.addField('Reason', `${reason}` )
.setFooter(`Banned by ${admin}`)
.setTimestamp()
user.send({ embeds: [embed4] })
setTimeout(function(){
user.ban().catch(err => console.log(err)).then(() => {
message.channel.send({ embeds: [embed3] })
message.channel.bulkDelete(1);
}, 20000);
})
}
}
}
}
Turns out I was looking to see if I had the roles with message.member
so i removed message
from it and changed member
to user
and turned the roles into an array to clean up the code abit