How to check if bot has higher role than mentioned user

Just RedX

I'm making a bot that's gonna have a few moderator commands. I need to check if the bot has a higher role than the tagged user.

My code:

        let mentionedRole = message.mentions.members.first().roles.highest
        let botRole = client.user.roles.highest

        if (mentionedRole.position > botRole.position) {
            message.channel.send(`I dont have access to mute this member.${message.author}`)
            return
        }

The error shown:

let botRole = client.user.roles.highest

TypeError: Cannot read properties of undefined (reading 'highest')

Gh0st

So this (at least in my own opinion) would I think be easier, I would do this:

if (!message.mentions.members.first().manageable) {
    // above if statement determines whether the client user is above this user in the hierarchy, according to role position and guild ownership.
    message.channel.send(`I dont have access to mute this member.${message.author}`)
    return
}

Discord.JS

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Spring security check if user has access to mentioned url

How to create bot command that give role to mentioned user | Discord.py

How to check if a specific user has a role? Discord js

How to check is an user has a role on discord

How to check if a user has a specific role in Meteor

Discordjs check if a user has a role

How to check if a user has a specific role in on_message?

In Angular -> how to check if the user has permission using role-based access with the role save in the data base

Check if User has a certain role

How to get the bot to recognize when a role was mentioned, and then respond back?

How to check if a user has a role from another Discord server

Discord bot, how do I assign a role to the user you mentioned?

How to check if a column in pandas dataframe has a value greater than mentioned value . If The column has values as lists

How do I check if the mentioned user has Administrator permission?

How to check if a member has mentioned a specific user?

So i want to make my bot do a callback like return if the mentioned user already has a role

How can I check if the user has a role for one to one relationship?

How to check if user has different role in mvc

Check if mentioned profile is a bot

How to detect if the bot has been mentioned?

Trying to add a role to a mentioned user

How can you check if a user has a particular role in a particular server

Discord.js-commando how would I check if a mentioned user has a role, like a muted role for example?

How do I check if a user has a role in discord.py?

To check if a mentioned user has the role or not in discord.js

How to check whether user has any role?

Discord.js how to check if user has a role on a specific server

How do I check message author's and mentioned user's highest role positions, and compare them?

Bot crashes if user has no role