Reputation: 81
I'm making a discord bot and there's a command where I want only admins to be able to use, but when I try to check if the user has a role, it says that it can't read the property 'roles' of undefined. Here's the code I'm using
if(command === '!cmd') {
if(message.author.id != ownerid || !message.member.roles.has(370565560972476437)) {
messagesend("YOU ARE NOT ALLOWED TO USE THIS COMMAND\nTHIS IS YOUR ONLY WARNING")
console.log(message.author);
} else if(message.author.id === ownerid || message.member.roles.has("370565560972476437") || message.member.roles.some(r=>["admin"].includes(r.name))) {
var messageArrray = messageArray.slice(1,messageArray.length)
let evalStr = ""
for(let element of messageArrray){
evalStr += element + " "
}
console.log(evalStr);
eval(evalStr)
message.delete()
}
}
Upvotes: 0
Views: 1893
Reputation: 86
if (message.guild.members.get(message.author.id).roles.exists('name','ROLENAME'){
///Code here
}
Thats all.
Upvotes: 1