Skip to content
Advertisement

role overwrites when creating a role discord.js

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?

Advertisement

Answer

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.
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement