最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin1浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论