如何检查机器人是否比提到的用户具有更高的角色

How to check if bot has higher role than mentioned user

我正在制作一个有一些版主命令的机器人。我需要检查机器人是否具有比标记用户更高的角色。

我的代码:

        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
        }

显示的错误:

let botRole = client.user.roles.highest

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

所以我认为这(至少在我自己看来)会更容易,我会这样做:

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