Find out if anyone has a role

I made a simple bot quote for the server, but the administrator wants the mod + people to be able to add quotes to avoid spam. I went to the documentation and did everything, but I cannot get this to work. Here is what I have:

//other code
else if (command === "addquote" && arg) {
    let adminRole = message.guild.roles.find("name", "Admin");
    let modRole = message.guild.roles.find("name", "Mod");

    if(message.member.roles.has(adminRole) || message.member.roles.has(modRole)){
        const hasArr = arr.some((el) => {
            return el.toLowerCase().replace(/\s/g, '') === arg.toLowerCase().replace(/\s/g, '');
        });

        if(hasArr){
            message.channel.send(arg.replace(/\s+/g,' ').trim() + " is already a Quote");
        } else {
            fs.appendFileSync('./Quotes.txt', '\r\n' + arg);
            message.channel.send("Quote added: " + arg);
            arr.push(arg);            
        }   
    }
}

This is very clever. Sometimes this will work if the user has a mod role, in most cases it will not. If i do

console.log(message.memeber.roles.has(adminRole));
console.log(message.memeber.roles.has(modRole));

both will be displayed on false, but will work? Honestly, I have no idea about this.

+5
source share
4 answers

The discord.js API has been updated and there is a better way since it is .exists()deprecated.

if (message.member.roles.some(role => role.name === 'Whatever')) {}

, .find() .find() ( ), . .some() .

0

message.member.roles - . , , . :

else if (command === "addquote" && arg) {
    if(message.member.roles.find("name", "Admin") || message.member.roles.find("name", "Mod")){
        //Rest of your code
    }

, , find, emojis, .

+9

Map.has , , .

message.member.roles.has(adminRole.id)

message.member.roles.has(modRole.id)

+3

if(message.guild.roles.find(role => role.name === "VIP"))

+1

Source: https://habr.com/ru/post/1682283/


All Articles