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!
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 below on creating new roles with the new RoleManager
object.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.