Checking if a user have a certain role in an array of role

Viewed 85

I am trying to make a command that is only available for certain roles only. I tried checking them in an array, but it doesn't seem to work.

the command:

const Command = require("../structures/Command.js");
const config = require("../data/config.json");

module.exports = new Command({
    name: "test",
    description: "test",

    async run(message, args, client) {
        if (message.author.bot) return;
        if (message.member.roles.cache.some(role => role.id === config.adminRoles)) {return message.reply("You have the admin role")} else {message.reply("No")}
    }
});

config.json

{
"token": "token_go_here",
"prefix": "ab!",
"adminRoles": ["931469781234769940","931462231969910794"],
}
2 Answers

There are several ways you can do this:

config.json

{
"token": "token_go_here",
"prefix": "ab!",
"admin1": "931469781234769940",
"admin2": "931462231969910794"
}

command.js

const Command = require("../structures/Command.js");
const { admin1, admin2 } = require("../data/config.json")

module.exports = new Command({
    name: "test",
    description: "test",

    async run(message, args, client) {
        if (message.author.bot) return;
        if (message.member.roles.cache.has(admin1) || message.member.roles.cache.has(admin2)) {
            return message.reply("You have the admin role")
        }
    }
});
Related