Discord.js give permission to a role and roles that are higher than that role

Basically, I want to make it so my JS bot gives permission to use commands if the member has a higher role than the specified role in the JS.

Example

if(role > specifiedrole){
gives permissions
} else if(role === specified role{
gives permissions
}

I’m new to JS so I don’t know much.

This may/may not work and if it does work it is probably very inefficient @Vaelkarr

let specifiedrole = message.guild.roles.find(role => role.name === "Name of Role")
message.guild.roles.forEach((role) =>{
if(message.member.roles.cache.has(role.id)) {
if(role.position>specifiedrole.position){
//give permission
}else if(role.id == specifiedrole.id){
//givepermission
}
}
})
2 Likes

You can use role positions. I don’t know it exactly, but you can see it here.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.