javascript - How to make discord bot role colored? - Stack Overflow

I am making a discord bot, and I was wondering if I could make it have its own role colour. for example

I am making a discord bot, and I was wondering if I could make it have its own role colour. for example, the mee6 bot always has a blue role colour when it joins a server, so I was wondering if I could do that too.

I have tried to look this up, but can't find anything that does this.

I am making a discord bot, and I was wondering if I could make it have its own role colour. for example, the mee6 bot always has a blue role colour when it joins a server, so I was wondering if I could do that too.

I have tried to look this up, but can't find anything that does this.

Share Improve this question asked Oct 7, 2020 at 13:31 JoshJosh 1393 silver badges11 bronze badges 1
  • 1 Is this not something assigned to the role in the settings on the server and not something that the bot can assign itself programmatically. – MT0 Commented Oct 7, 2020 at 13:35
Add a ment  | 

3 Answers 3

Reset to default 4

You cannot modify the color of the bot's actual role, but you can create a role with a color and assign it to the bot when it joins a guild. Here are some examples from my casino discord bot:

For the latest version of discord.js:

client.on('guildCreate', guild => {
    guild.roles.create({
        data: {
            name: "Casino",
            color: "#593695"
        }
    }).then(role => guild.member(client.user).roles.add(role)).catch(console.error);
});

For discord.js v11.6.4:

client.on('guildCreate', guild => {
    guild.createRole({
        name: "Casino",
        color: "#593695"
    }).then(role => guild.member(client.user).addRole(role)).catch(console.error);
});

This adds a purple-colored role to the bot when it joins the server. Of course, your bot must have the manage roles permission to do this and if you get errors, your bot is probably missing that permission.

This is impossible, as the role color can only be changed by a server admin.

for example, the mee6 bot always has a blue role colour when it joins a server, so I was wondering if I could do that too.

I just added it to my server, and it stayed white...

The bot is able to make a new role with any color you want.

// Create a new role with data and a reason
guild.roles.create({
  data: {
    name: 'Super Cool People',
    color: 'BLUE',
  },
  reason: 'we needed a role for Super Cool People',
})
  .then(console.log)
  .catch(console.error);

Source: https://discord.js/#/docs/main/stable/class/RoleManager?scrollTo=create

You're also able to edit a role that already exists:

// Edit a role
role.edit({ name: 'new role' })
  .then(updated => console.log(`Edited role ${updated.name} name to ${updated.name}`))
  .catch(console.error);

Source: https://discord.js/#/docs/main/stable/class/Role?scrollTo=edit

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745561780a4633149.html

相关推荐

  • javascript - How to make discord bot role colored? - Stack Overflow

    I am making a discord bot, and I was wondering if I could make it have its own role colour. for example

    8小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信