Find out if someone has a role
The discord.js api has been updated and there is a better way since .exists()
has been deprecated.
if (message.member.roles.cache.some(role => role.name === 'Whatever')) {}
This is better than .find()
because .find()
returns the role object (or undefined) which is then converted into a boolean. The .some()
method returns a boolean by default.
This worked for me with version 12.2.0
if(message.member.roles.cache.find(r => r.name === "Admin")) {
// Your code
}
You can also use r.id
to check with the role id
message.member.roles
is a collection. Instead of getting the roles object, then looking for it, just look for the role directly in the collection. Try this:
else if (command === "addquote" && arg) {
if(message.member.roles.find(r => r.name === "Admin") || message.member.roles.find(r => r.name === "Mod")){
// The rest of your code.
}
Note, the role name must be the name you put in the find method, including any emojis if there's any in the role name.