Hello I have problem with my code! When I use my mute command it always spams "You need permission to use command"! Here is my code:
client.on('message', message => {
if(message.content.startsWith("$mute")) {
if (!message.member.permissions.has("KICK_MEMBERS")) return
message.channel.send("You need permissions to use command")
let role = message.guild.roles.cache.find(role => role.name === "Muted")
let member = message.mentions.members.first()
let reason = message.content.split(" ").slice(2).join(" ")
if(!reason) return message.channel.send("You didn't write a reason")
if(!role) return message.channel.send("This server don't have Muted role")
if(!member) return message.channel.send("You didn't mention the user to mute!")
member.roles.add(role)
.then(() => {
message.channel.send(`Successfully muted ${member} with reason: ${reason}`)
})
.catch(() => {
message.channel.send("Error")
})
}
})
CodePudding user response:
if (!message.member.permissions.has("KICK_MEMBERS")) return
message.channel.send("You need permissions to use command")
This translates to "If the member doesn't have the permission to kick other members, exit the function and return undefined. Else, if the member HAS permission, send a message saying he DOESN'T have permission".
if (!message.member.permissions.has("KICK_MEMBERS")) return message.channel.send("You need permissions to use command")
You should write it like this instead.