Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Mute system discord.js

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")
    })
 }
})

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading