简体   繁体   English

角色定位:Discord.js

[英]Role Positions: Discord.js

I am trying to create roles in my server via my bot in a certain order, but every time i run the command the role positions are all wrong.我试图通过我的机器人按特定顺序在我的服务器中创建角色,但是每次我运行命令时,角色位置都是错误的。

Code:代码:

client.on("message", message => {
    if(message.content.startsWith(prefix + "createrole")){
        message.guild.roles.create({
            data: {
                name: "Owner",
                color: "BLUE",
                position: 1
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
        message.guild.roles.create({
            data: {
                name: "Admin",
                color: "BLUE",
                position: 2
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
        message.guild.roles.create({
            data: {
                name: "Mod",
                color: "BLUE",
                position: 3
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
    }
})

在此处输入图片说明

In Theory this should be in order but I am not sure what is going on !从理论上讲,这应该是有序的,但我不确定发生了什么!

Any help would be appreciated.任何帮助,将不胜感激。

Interesting that it gives that output, considering how roles are indexed.有趣的是,它给出了输出,考虑到角色是如何被索引的。 Please note that roles are indexed based on the @everyone role, for your owner role to be above your admin role it must have a higher position number.请注意,角色是根据@everyone角色编入索引的, @everyone您的所有者角色高于您的管理员角色,它必须具有更高的职位编号。 Upsettingly, I can't seem to find anything that describes this behavior, however testing does provide this behavior.令人不安的是,我似乎找不到任何描述这种行为的东西,但是测试确实提供了这种行为。

Setting Owner to 3, Admin to 2, and Mod to 1 should give your desired results.将 Owner 设置为 3,Admin 设置为 2,Mod 设置为 1 应该会得到您想要的结果。

不和谐角色顺序

... it is still really odd that Mod ends up above Owner with your current position values, but it is what it is I guess. ... Mod 最终以您当前的位置值高于 Owner 仍然奇怪,但我猜这就是它。

Seems that role create method and its data properties for position are indexed in a odd way and its indexed by 2 for a role to be higher than another.似乎角色创建方法及其位置的数据属性以奇怪的方式索引,并且它的索引为 2 以表示角色高于另一个角色。

code:代码:

 if(message.content.startsWith(prefix + "createrole")){
        message.guild.roles.create({
            data: {
                name: "Owner",
                color: "BLUE",
                position: 5
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
        message.guild.roles.create({
            data: {
                name: "Admin",
                color: "BLUE",
                position: 3
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
        message.guild.roles.create({
            data: {
                name: "Mod",
                color: "BLUE",
                position: 1
            }
        })
        .then(role => console.log(red(`Role created`)))
        .catch(err => console.log(err))
        
    }

Result:结果:

在此处输入图片说明

This is still very confusing to me but it is what it is.这对我来说仍然很困惑,但事实就是如此。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM