discord.js create role code example
Example 1: discord javascript how to create a role
// 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);
Example 2: if member has role discord.js
let allowedRole = message.guild.roles.find("name", "rolename");
if (message.member.roles.has(allowedRole.id) {
// allowed access to command
} else {
// not allowed access
})
Example 3: how to give a role to a new member in discord.js
var role = message.guild.roles.find(role => role.name === "MyRole");
message.member.addRole(role);