I'm currently working on a discord bot that has multiple commands that are only for specific roles. I currently have all roles that are allowed to use the commands in an array and my code below works.
for (var i = 0; i < Config.AllowedRanks.length; i++) {
if (message.member.roles.cache.has(Config.AllowedRanks[i])){
console.log("Access Granted")
}
}
But how do I make it so that everyone else that doesn't have the role, gets a message that the access is denied? The code below does the thing I want but also does it when someone has the role when that role is not first in the array.
for (var i = 0; i < Config.AllowedRanks.length; i++) {
if (message.member.roles.cache.has(Config.AllowedRanks[i])){
console.log("Access Granted")
} else{
console.log("Access Denied")
}
}
The answer thanks to Bqre:
if (Config.AllowedRanks.some(role => message.member.roles.cache.get(role))){
console.log("Access Granted")
} else{
console.log("Access Denied")
}