I made a simple quote bot for a server, but the admin only wants mod+ people to be able to add quotes to avoid spam. I went to the documentation and did everything, but I ca
The discord.js api has been updated and there is a better way since .exists()
has been deprecated.
if (message.member.roles.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.
I'm probably wayy to late with this, but I just had the same problem, and the way i solved it is to search for the role, and then check if the variable has anything on it. Say i wanna check for if the author of the message has admin role:
client.on('message',message =>{
adminrole = message.member.roles.cache.find(role => role.name == "Admin");
if(adminrole != null){memberIsAdmin = true;}else{memberIsAdmin = false;}
}
Maybe this will help someone, note that I'm not very experienced with js tho :) Have a nice day y'all
The Map.has method checks for keys, not values, so you'll have to use the roles' ids instead.
message.member.roles.has(adminRole.id)
message.member.roles.has(modRole.id)
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
if(message.guild.roles.find(role => role.name === "VIP"))
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 => rname === "Mod")){
//Rest of your code
}
Note, the role name must be the name you put in the find including any emojis if there's any in the role name.