class Role
extends
Baseexport class Role extends BaseRepresents a role on Discord.
color : number
The base 10 color of the role
readonlycreatedAt : Date
The time the role was created at
readonlycreatedTimestamp : number
The timestamp the role was created at
readonlyeditable : boolean
Whether the role is editable by the client user
flags : RoleFlagsBitField
The flags of this role
guild : Guild
The guild that the role belongs to
readonlyhexColor : HexColorString
The hexadecimal version of the role color, with a leading hashtag
hoist : boolean
If true, users that are part of this role will appear in a separate category in the users list
id : Snowflake
The role's id (unique to the guild it is part of)
managed : boolean
Whether or not the role is managed by an external service
readonlymembers : Collection<Snowflake, GuildMember>
The cached guild members that have this role
mentionable : boolean
Whether or not the role can be mentioned by anyone
name : string
The name of the role
permissions : Readonly<PermissionsBitField>
The permissions of the role
readonlyposition : number
The position of the role in the role manager
rawPosition : number
The raw position of the role from the API
tags : RoleTagData | null
The tags this role has
comparePositionTo(role: 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); edit(options: 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.
iconURL(options?: ImageURLOptions) : string | null
A link to the role's icon
permissionsIn(channel: NonThreadGuildBasedChannel | SnowflakecheckAdmin?: boolean) : Readonly<PermissionsBitField>
Returns channel.permissionsFor(role). Returns permissions for a role in a guild channel, taking into account permission overwrites.
setColor(color: 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); setIcon(icon: 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); setPermissions(permissions: 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); setPosition(position: 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);toJSON() : unknown
toString() : RoleMention
When concatenated with a string, this automatically returns the role's mention instead of the Role object.
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);