role overwrites when creating a role discord.js

痞子三分冷 提交于 2021-02-17 05:10:14

问题


When my bot joins a new guild it creates a role & sets overwrites.

client.on("guildCreate", async guild => {
      guild.roles.create({
        data: {
            name: "Billy 🤩", //sets the role name
            color: "#e5f7b2", //sets the color of the role
            permissions: 8    //sets the roles permissions to administrator
        }
      }).then(role => guild.member(client.user).roles.add(role)).catch(console.error);
  });

I have 2 questions:
Is it possible to move this role to the top of the list or at least somewhere close?
How would I go on displaying this role separately from online members?


回答1:


To display a role separately from online members, you can use the Role#setHoist method.

Role.setHoist(true);

You cannot move a role above your bot's highest role in the roles hierarchy.

I recommend you to get your bot's highest role, get its position, and set your role's position accordingly.

const Role = Guild.roles.cache.get("1234567890123456"); // The role you want to update.

const HighestRole = Guild.me.roles.highest; // Your bot's highest role in the Guid.

Role.setPosition(HighestRole.position - 1); // Setting the role's position right before your HighestRole.


来源:https://stackoverflow.com/questions/64416160/role-overwrites-when-creating-a-role-discord-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!