0
votes

How can I make my bot not take the message authors highest role if they tried?

I tried using if(message.member.roles.highest.position = gRole.position), but it didn't work.

My code:

  
   if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send("You don't have permissions to use this!");
  
  let member = message.mentions.members.first()
    if(!member) return message.channel.send("You must mention a user to assign/remove roles to/from")
  
      if(message.member.roles.highest.position < member.roles.highest.position) return message.channel.send("You cannot assign/remove roles of someone with a role higher than you")  
  
  let role = args[2]
  if(!role) return message.channel.send("Provide a role name to assign/remove")
  
  let gRole = message.guild.roles.cache.find(r => r.name.toLowerCase() === role.toLowerCase())
  
      if(message.member.roles.highest.position < gRole.position) {
message.channel.send("That role is above your highest role, it can't be managed")
  } else {

}
  
    if(!gRole) return message.channel.send(`The role \`${role}\` could not be found`)
  
        if(message.member.roles.highest.position > gRole.position) {
  if(!member.roles.cache.has(gRole.id)) {
await member.roles.add(gRole.id)
    message.channel.send(`The role \`${role}\` has been added to **${member.user.username}**`)
} else {
await member.roles.remove(gRole.id)
    message.channel.send(`The role \`${role}\` has been removed from **${member.user.username}**`)
}
    } 
}

module.exports.help = {
  name: "role"
}
1

1 Answers

1
votes

Give if (message.member.roles.highest.position === gRole.position) a try.

A single = is used for defining variables. In order to compare values, you should use either == or ===.