I have a command where my bot is supposed to give a person that I mention in my message a role, the bot gives the user the role just fine. However when I run the command on someone who already has the role it doesn't stop and say "user already has role", it continues and says it added the role to the user
.
Here's my code:
module.exports = {
name: 'pm',
description: 'sets pm',
permissions: ['ADMINISTRATOR'],
execute(client, message, args, Discord){
try {
let role = message.guild.roles.cache.get("role id");
let member = message.mentions.members.first();
if(!member) return message.channel.send('***Error:*** Please specify a user.');
if(member.roles.cache.has(role)) {
message.channel.send(`***Error:*** ${member} is already a PM.`)
} else {
member.roles.add(role);
message.channel.send(`Added ${member}`)
}
} catch (e) {
message.channel.send(`***Error:*** ${e}`)
console.log(e)
}
}
}