Role
classe · Source
Represents a role on Discord.
Extends: Base
Properties
guild
The guild that the role belongs to Source
icon
The icon hash of the role Source
unicodeEmoji
The unicode emoji for the role Source
id
The role's id (unique to the guild it is part of) Source
name
The name of the role Source
color
The base 10 color of the role Source
colors
The colors of the role Source
hoist
If true, users that are part of this role will appear in a separate category in the users list Source
rawPosition
The raw position of the role from the API Source
permissions
The permissions of the role Source
managed
Whether or not the role is managed by an external service Source
mentionable
Whether or not the role can be mentioned by anyone Source
tags
The tags this role has Source
flags
The flags of this role Source
createdTimestamp
The timestamp the role was created at Source
createdAt
The time the role was created at Source
deleted
Whether or not the role has been deleted Source
hexColor
The hexadecimal version of the role color, with a leading hashtag Source
members
The cached guild members that have this role Source
editable
Whether the role is editable by the client user Source
position
The position of the role in the role manager Source
client
The client that instantiated this Source
Methods
comparePositionTo
Compares this role's position to another role's. Parameters
| Name | Type | Description |
|---|---|---|
role | RoleResolvable | Role to compare to this one |
Returns: number — 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
// 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}`);edit
Edits the role. Parameters
| Name | Type | Description |
|---|---|---|
data | RoleData | The new data for the role |
reason? | string | Reason for editing this role |
Returns: Promise<Role>
// Edit a role
role.edit({ name: 'new role' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);permissionsIn
Returns channel.permissionsFor(role). Returns permissions for a role in a guild channel, taking into account permission overwrites. Parameters
| Name | Type | Description |
|---|---|---|
channel | GuildChannel | Snowflake | The guild channel to use as context |
checkAdmin? | boolean | Whether having ADMINISTRATOR will return all permissions Default: true. |
Returns: Readonly<Permissions>Source
setName
Sets a new name for the role. Parameters
| Name | Type | Description |
|---|---|---|
name | string | The new name of the role |
reason? | string | Reason for changing the role's name |
Returns: Promise<Role>
// Set the name of the role
role.setName('new role')
.then(updated => console.log(`Updated role name to ${updated.name}`))
.catch(console.error);setColor
Sets a new color for the role. Parameters
| Name | Type | Description |
|---|---|---|
color | ColorResolvable | The color of the role |
reason? | string | Reason for changing the role's color |
Returns: Promise<Role>Source
setColors
Sets new colors for the role. Parameters
| Name | Type | Description |
|---|---|---|
colors | RoleColorsResolvable | The colors of the role |
reason? | string | Reason for changing the role's colors |
Returns: Promise<Role>
// Set the colors of a role
role.setColors({ primaryColor: '#FF0000', secondaryColor: '#00FF00', tertiaryColor: '#0000FF' })
.then(updated => console.log(`Set colors of role to ${updated.colors}`))
.catch(console.error);// Set holographic colors using constants
role.setColors({
primaryColor: Constants.HolographicStyle.Primary,
secondaryColor: Constants.HolographicStyle.Secondary,
tertiaryColor: Constants.HolographicStyle.Tertiary,
})
.then(updated => console.log(`Set holographic colors for role ${updated.name}`))
.catch(console.error);setHoist
Sets whether or not the role should be hoisted. Parameters
| Name | Type | Description |
|---|---|---|
hoist? | boolean | Whether or not to hoist the role Default: true. |
reason? | string | Reason for setting whether or not the role should be hoisted |
Returns: Promise<Role>
// Set the hoist of the role
role.setHoist(true)
.then(updated => console.log(`Role hoisted: ${updated.hoist}`))
.catch(console.error);setPermissions
Sets the permissions of the role. Parameters
| Name | Type | Description |
|---|---|---|
permissions | PermissionResolvable | The permissions of the role |
reason? | string | Reason for changing the role's permissions |
Returns: Promise<Role>
// Set the permissions of the role
role.setPermissions([Permissions.FLAGS.KICK_MEMBERS, Permissions.FLAGS.BAN_MEMBERS])
.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);setMentionable
Sets whether this role is mentionable. Parameters
| Name | Type | Description |
|---|---|---|
mentionable? | boolean | Whether this role should be mentionable Default: true. |
reason? | string | Reason for setting whether or not this role should be mentionable |
Returns: Promise<Role>
// Make the role mentionable
role.setMentionable(true)
.then(updated => console.log(`Role updated ${updated.name}`))
.catch(console.error);setIcon
Sets a new icon for the role. Parameters
| Name | Type | Description |
|---|---|---|
icon | BufferResolvable | Base64Resolvable | EmojiResolvable | The icon for the role The EmojiResolvable should belong to the same guild as the role.If not, pass the emoji's URL directly |
reason? | string | Reason for changing the role's icon |
Returns: Promise<Role>Source
setUnicodeEmoji
Sets a new unicode emoji for the role. Parameters
| Name | Type | Description |
|---|---|---|
unicodeEmoji | string | The new unicode emoji for the role |
reason? | string | Reason for changing the role's unicode emoji |
Returns: Promise<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);setPosition
Sets the new position of the role. Parameters
| Name | Type | Description |
|---|---|---|
position | number | The new position for the role |
options? | SetRolePositionOptions | Options for setting the position |
Returns: Promise<Role>
// Set the position of the role
role.setPosition(1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);delete
Deletes the role. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for deleting this role |
Returns: Promise<Role>
// Delete a role
role.delete('The role needed to go')
.then(deleted => console.log(`Deleted role ${deleted.name}`))
.catch(console.error);fetchMemberIds
Fetches the member ids for this role in the guild. This only returns 100 member ids Returns: Promise<Array<Snowflake>>Source
iconURL
A link to the role's icon Parameters
| Name | Type | Description |
|---|---|---|
options? | StaticImageURLOptions | Options for the image URL Default: {}. |
Returns: stringSource
equals
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. Parameters
| Name | Type | Description |
|---|---|---|
role | Role | Role to compare with |
Returns: booleanSource
toString
When concatenated with a string, this automatically returns the role's mention instead of the Role object. Returns: string
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);comparePositions
Compares the positions of two roles. Parameters
| Name | Type | Description |
|---|---|---|
role1 | Role | First role to compare |
role2 | Role | Second role to compare |
Returns: number — Negative number if the first role's position is lower (second role's is higher), positive number if the first's is higher (second's is lower), 0 if equal Source