its driving me insane! i dont know what to do ive tried everything this is the code used, there is nothing (i think) thats causing it to repeat, matter 'a fact i added something so it stops repeating but it didn't do anything. at all.
client.on('message', e =>{
if(e.member.roles.cache.has('12345678901')){
if(!e.content.startsWith(p) || e.author.bot) return;
console.log('successfully unmuted')
var ar = e.content.slice(p.length).split(/ /)
var cmd = ar.shift().toLowerCase();
if(cmd === 'b'){
console.log('succesfully banned')
var member = e.mentions.users.first();
if(member){
var membertarget = e.guild.members.cache.get(member.id)
membertarget.ban();
var sbbed = new discord.MessageEmbed()
.setColor('GREEN')
.setTitle('success!')
.setDescription(`<@${membertarget.user.id}> has been successfully banned!`)
}else {
var bbed = new discord.MessageEmbed()
.setColor('RED')
.setTitle('invalid user!')
.setDescription('ban failed because there was not a valid member mentioned :(')
e.channel.send({ embeds: [bbed] })
}
}
} else {
var rolefb = new discord.MessageEmbed()
.setColor('RED')
.setTitle('failed!')
.setDescription('sorry! you dont have a high enough role to use this command, but this can change!')
if (e.author.bot) return;
e.channel.send({embeds: [rolefb]})
}
})
this code is supposed to just ban somebody but it keeps repeating itself whenever it fails
it would mean everything if someone just helped!
client.on('message', e =>{
if (e.author.bot) return
if(e.member.roles.cache.has('960191891473829929')){
edited, but still doesnt work
CodePudding user response:
Your code runs whenever a message is posted in your server so the bot sending the message will also be counted. So all you have to do is add an if check in the start to check whether the author of the message was a bot:
if (message.author.bot) return
CodePudding user response:
Try to add this statement to your code before if(e.member.roles.cache.has('12345678901')){
if (e.author == client.user) return;
Also, change the if(e.member.roles.cache.has('12345678901')){
to else if (e.member.roles.cache.has('12345678901')){
.
I would recommend restructuring the entire code and make it into a command handler, though.