admin管理员组

文章数量:1201375

I've been trying to make a discord bot using discord.js, but I can't seem to find any documentation on how to create a role that works in 2018. All the ones I can find that work, no longer work as they have removed the referenced function. In there is no mention of a createRole("role", "roleName"); type function.

If anyone could help that would be great!

I've been trying to make a discord bot using discord.js, but I can't seem to find any documentation on how to create a role that works in 2018. All the ones I can find that work, no longer work as they have removed the referenced function. In https://discord.js.org/#/docs/main/stable/class/Role there is no mention of a createRole("role", "roleName"); type function.

If anyone could help that would be great!

Share Improve this question asked Nov 15, 2018 at 23:33 6IU6IU 1352 gold badges2 silver badges7 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 18

Guild.createRole does not appear to exist in 2020. Instead, it seems that you can get a reference to a RoleManager object via the property Guild.roles, and then call create on the RoleManager object:

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

From their docs:

// 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);

The class Role does not have the method to create a new role, you must look at the Guild class for that. Here is a link to the documentation for the method: https://discord.js.org/#/docs/main/stable/class/Guild?scrollTo=createRole. Feel free to comment back if you have any questions!

Edit: As of discord.js v12, createRole no longer exists, please refer to cecomp64's answer above on creating new roles with the new RoleManager object.

本文标签: javascriptHow to create a role with discordjsStack Overflow