久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

用戶角色層次結(jié)構(gòu)

User role-hierarchy(用戶角色層次結(jié)構(gòu))
本文介紹了用戶角色層次結(jié)構(gòu)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

由于像這樣 https://media.discordapp.net/attachments/223867697312694272/723382952330919976/image0.png

相反,我的機器人允許用戶將上面的角色添加給他們自己或其他用戶,只要他們具有所需的權(quán)限 https://cdn.discordapp.com/attachments/223867697312694272/723382993384767550/image0.png

Instead my bot allows the user to add the role above them to themselves or other users as long as they have the required permissions https://cdn.discordapp.com/attachments/223867697312694272/723382993384767550/image0.png

我的代碼:

const Discord = require("discord.js");

module.exports.run = async (bot, message, args) => {

    if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send("You don't have permissions to use this!");

    let xdemb = new Discord.RichEmbed()
        .setColor("RANDOM")
        .setTitle("Role Command")
        .addField("Description:", `Adds/removes a role to/from a member`, true)
        .addField("Usage:", "`?role` [user] roleName", true)
        .addField("Example:" ,"`?role` @user goodrole", true)

    let member = message.mentions.members.first();
    if(!member) return message.channel.send(xdemb)

    let role = args.slice(2).join(" ")
    if(!role) return message.channel.send("Provide a role to assign")

    let gRole = message.guild.roles.find(r => r.name.toLowerCase() === role.toLowerCase())
    if(!gRole) return message.channel.send(`There's no role with the name `${role}``)


    if(member.roles.has(gRole.id)) {
        member.removeRole(gRole.id)
        message.channel.send(`Removed role `${role}` from **${member.user.username}**`)
    } else {
        member.addRole(gRole.id)
        message.channel.send(`Added role `${role}` to **${member.user.username}**`)
    }
}

module.exports.help = {
    name: "role"
}

推薦答案

Discord.js 中的 Role 類有一個 position 屬性,表示其在角色管理器中的位置.

The Role class in Discord.js has a position property which represents its position in the role manager.

GuildMember 類有一個名為 roles,它的類型是 GuildMemberRoleManager.GuildMemberRoleManager 類有一個名為 highest,指向成員擁有的排名最高的角色.

The GuildMember class has a property named roles, which is of type GuildMemberRoleManager. The GuildMemberRoleManager class has a property named highest, which points to the highest ranked role that the member has.

所以.為了確保機器人不會在層次結(jié)構(gòu)中為成員提供比他們更高的角色,您可以將他們想要的角色的 positionposition 進行比較他們目前的最高職位.

So. To make sure that the bot doesn't give a member a role that is higher than them in the hierarchy, you can compare the position of the role they want with the position of their current highest role.

這篇關(guān)于用戶角色層次結(jié)構(gòu)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

discord.js v12: How do I await for messages in a DM channel?(discord.js v12:我如何等待 DM 頻道中的消息?)
how to make my bot mention the person who gave that bot command(如何讓我的機器人提及發(fā)出該機器人命令的人)
How to fix Must use import to load ES Module discord.js(如何修復(fù)必須使用導(dǎo)入來加載 ES 模塊 discord.js)
How to list all members from a specific server?(如何列出來自特定服務(wù)器的所有成員?)
Discord bot: Fix ‘FFMPEG not found’(Discord bot:修復(fù)“找不到 FFMPEG)
Welcome message when joining discord Server using discord.js(使用 discord.js 加入 discord 服務(wù)器時的歡迎消息)
主站蜘蛛池模板: 日韩精品久久久 | 亚洲精品乱码久久久久久按摩观 | 国产激情精品一区二区三区 | 一区二区在线 | 亚洲伊人精品酒店 | 99re6在线视频精品免费 | 97日日碰人人模人人澡分享吧 | 精品在线一区二区三区 | 久久精品视频91 | 天天干在线播放 | 国产精品日韩一区二区 | 国产 日韩 欧美 在线 | 成人h视频在线观看 | 日韩欧美三区 | 精品在线观看入口 | 国内精品久久精品 | 视频在线观看一区 | 国产在线一区二区三区 | a视频在线观看 | 五月婷婷在线播放 | 亚洲欧洲精品一区 | 操操日| 久久久一区二区三区四区 | 365夜爽爽欧美性午夜免费视频 | 台湾a级理论片在线观看 | 精品一区二区在线观看 | 国产免费拔擦拔擦8x高清 | 国产精品综合久久 | 欧美日韩视频 | 久久av在线播放 | 国产女人精品视频 | 日本免费一区二区三区四区 | 午夜免费视频 | 成人超碰 | 欧美日韩综合一区 | av网站免费看 | 人人射人人 | 日本网站免费观看 | 国产精品美女久久久免费 | 九色综合网 | 四虎影院欧美 |