class Role
extends
Baseexport class Role extends Base
Represents a role on Discord.
number color :
The base 10 color of the role
readonlyDate createdAt :
The time the role was created at
readonlynumber createdTimestamp :
The timestamp the role was created at
readonlyboolean editable :
Whether the role is editable by the client user
RoleFlagsBitField flags :
The flags of this role
Guild guild :
The guild that the role belongs to
readonlyHexColorString hexColor :
The hexadecimal version of the role color, with a leading hashtag
boolean hoist :
If true, users that are part of this role will appear in a separate category in the users list
Snowflake id :
The role's id (unique to the guild it is part of)
boolean managed :
Whether or not the role is managed by an external service
readonlyCollection<Snowflake, GuildMember> members :
The cached guild members that have this role
boolean mentionable :
Whether or not the role can be mentioned by anyone
string name :
The name of the role
Readonly<PermissionsBitField> permissions :
The permissions of the role
readonlynumber position :
The position of the role in the role manager
number rawPosition :
The raw position of the role from the API
RoleTagData | null tags :
The tags this role has
comparePositionTorole: RoleResolvable) : number (
Compares this role's position to another role's.
// Compare the position of a role to another
const roleCompare = role.comparePositionTo(otherRole);
if (roleCompare >= 1) console.log(`${role.name} is higher than ${otherRole.name}`);
Returns: Negative number if this role's position is lower (other role's is higher), positive number if this one is higher (other's is lower), 0 if equal
Deletes the role.
// Delete a role
role.delete('The role needed to go')
.then(deleted => console.log(`Deleted role ${deleted.name}`))
.catch(console.error);
editoptions: RoleEditOptions) : Promise<Role> (
Edits the role.
// Edit a role
role.edit({ name: 'new role' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
Whether this role equals another role. It compares all properties, so for most operations it is advisable to just compare role.id === role2.id
as it is much faster and is often what most users need.
iconURLoptions?: ImageURLOptions = {}) : string | null (
A link to the role's icon
permissionsInchannel: NonThreadGuildBasedChannel | SnowflakecheckAdmin?: boolean = true) : Readonly<PermissionsBitField> (
Returns channel.permissionsFor(role)
. Returns permissions for a role in a guild channel, taking into account permission overwrites.
setColorcolor: ColorResolvablereason?: string) : Promise<Role> (
Sets a new color for the role.
// Set the color of a role
role.setColor('#FF0000')
.then(updated => console.log(`Set color of role to ${updated.color}`))
.catch(console.error);
Sets whether or not the role should be hoisted.
// Set the hoist of the role
role.setHoist(true)
.then(updated => console.log(`Role hoisted: ${updated.hoist}`))
.catch(console.error);
setIconicon: BufferResolvable | Base64Resolvable | EmojiResolvable | nullreason?: string) : Promise<Role> (
Sets a new icon for the role.
Sets whether this role is mentionable.
// Make the role mentionable
role.setMentionable(true)
.then(updated => console.log(`Role updated ${updated.name}`))
.catch(console.error);
Sets a new name for the role.
// Set the name of the role
role.setName('new role')
.then(updated => console.log(`Updated role name to ${updated.name}`))
.catch(console.error);
setPermissionspermissions: PermissionResolvablereason?: string) : Promise<Role> (
Sets the permissions of the role.
// Set the permissions of the role
role.setPermissions([PermissionFlagsBits.KickMembers, PermissionFlagsBits.BanMembers])
.then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`))
.catch(console.error);
// Remove all permissions from a role
role.setPermissions(0n)
.then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`))
.catch(console.error);
setPositionposition: numberoptions?: SetRolePositionOptions) : Promise<Role> (
Sets the new position of the role.
// Set the position of the role
role.setPosition(1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
Sets a new unicode emoji for the role.
// Set a new unicode emoji for the role
role.setUnicodeEmoji('🤖')
.then(updated => console.log(`Set unicode emoji for the role to ${updated.unicodeEmoji}`))
.catch(console.error);
toJSONunknown () :
toStringRoleMention () :
When concatenated with a string, this automatically returns the role's mention instead of the Role object.
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);