Class: Role

Role

Represents a role on Discord.

Constructor

new Role(client, data, guild)

Parameters:
Name Type Description
client Client The instantiating client
data Object The data for the role
guild Guild The guild the role is part of
Source:

Extends

Members

(readonly) client :Client

The client that instantiated this
Type:
Overrides:
Source:

color :number

The base 10 color of the role
Type:
  • number
Source:

(readonly) createdAt :Date

The time the role was created at
Type:
  • Date
Source:

(readonly) createdTimestamp :number

The timestamp the role was created at
Type:
  • number
Source:

deleted :boolean

Whether the role has been deleted
Type:
  • boolean
Source:

(readonly) editable :boolean

Whether the role is editable by the client user
Type:
  • boolean
Source:

guild :Guild

The guild that the role belongs to
Type:
Source:

(readonly) hexColor :string

The hexadecimal version of the role color, with a leading hashtag
Type:
  • string
Source:

hoist :boolean

If true, users that are part of this role will appear in a separate category in the users list
Type:
  • boolean
Source:

id :Snowflake

The ID of the role (unique to the guild it is part of)
Type:
Source:

managed :boolean

Whether or not the role is managed by an external service
Type:
  • boolean
Source:

(readonly) members :Collection.<Snowflake, GuildMember>

The cached guild members that have this role
Type:
Source:

mentionable :boolean

Whether or not the role can be mentioned by anyone
Type:
  • boolean
Source:

name :string

The name of the role
Type:
  • string
Source:

permissions :Readonly.<Permissions>

The permissions of the role
Type:
Source:

(readonly) position :number

The position of the role in the role manager
Type:
  • number
Source:

rawPosition :number

The raw position of the role from the API
Type:
  • number
Source:

Methods

(static) comparePositions(role1, role2) → {number}

Compares the positions of two roles.
Parameters:
Name Type Description
role1 Role First role to compare
role2 Role Second role to compare
Source:
Returns:
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
Type
number

comparePositionTo(role) → {number}

Compares this role's position to another role's.
Parameters:
Name Type Description
role RoleResolvable Role to compare to this one
Source:
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
Type
number

delete(reasonopt) → {Promise.<Role>}

Deletes the role.
Parameters:
Name Type Attributes Description
reason string <optional>
Reason for deleting this role
Source:
Returns:
Type
Promise.<Role>
Example
// Delete a role
role.delete('The role needed to go')
  .then(deleted => console.log(`Deleted role ${deleted.name}`))
  .catch(console.error);

edit(data, reasonopt) → {Promise.<Role>}

Edits the role.
Parameters:
Name Type Attributes Description
data RoleData The new data for the role
reason string <optional>
Reason for editing this role
Source:
Returns:
Type
Promise.<Role>
Example
// Edit a role
role.edit({ name: 'new role' })
  .then(updated => console.log(`Edited role ${updated.name} name to ${updated.name}`))
  .catch(console.error);

equals(role) → {boolean}

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
Source:
Returns:
Type
boolean

permissionsIn(channel) → {Readonly.<Permissions>}

Returns `channel.permissionsFor(role)`. Returns permissions for a role in a guild channel, taking into account permission overwrites.
Parameters:
Name Type Description
channel ChannelResolvable The guild channel to use as context
Source:
Returns:
Type
Readonly.<Permissions>

setColor(color, reasonopt) → {Promise.<Role>}

Sets a new color for the role.
Parameters:
Name Type Attributes Description
color ColorResolvable The color of the role
reason string <optional>
Reason for changing the role's color
Source:
Returns:
Type
Promise.<Role>
Example
// Set the color of a role
role.setColor('#FF0000')
  .then(updated => console.log(`Set color of role to ${updated.color}`))
  .catch(console.error);

setHoist(hoist, reasonopt) → {Promise.<Role>}

Sets whether or not the role should be hoisted.
Parameters:
Name Type Attributes Description
hoist boolean Whether or not to hoist the role
reason string <optional>
Reason for setting whether or not the role should be hoisted
Source:
Returns:
Type
Promise.<Role>
Example
// Set the hoist of the role
role.setHoist(true)
  .then(r => console.log(`Role hoisted: ${r.hoist}`))
  .catch(console.error);

setMentionable(mentionable, reasonopt) → {Promise.<Role>}

Sets whether this role is mentionable.
Parameters:
Name Type Attributes Description
mentionable boolean Whether this role should be mentionable
reason string <optional>
Reason for setting whether or not this role should be mentionable
Source:
Returns:
Type
Promise.<Role>
Example
// Make the role mentionable
role.setMentionable(true)
  .then(updated => console.log(`Role updated ${updated.name}`))
  .catch(console.error);

setName(name, reasonopt) → {Promise.<Role>}

Sets a new name for the role.
Parameters:
Name Type Attributes Description
name string The new name of the role
reason string <optional>
Reason for changing the role's name
Source:
Returns:
Type
Promise.<Role>
Example
// Set the name of the role
role.setName('new role')
  .then(updated => console.log(`Edited name of role ${role.name} to ${updated.name}`))
  .catch(console.error);

setPermissions(permissions, reasonopt) → {Promise.<Role>}

Sets the permissions of the role.
Parameters:
Name Type Attributes Description
permissions PermissionResolvable The permissions of the role
reason string <optional>
Reason for changing the role's permissions
Source:
Returns:
Type
Promise.<Role>
Examples
// Set the permissions of the role
role.setPermissions(['KICK_MEMBERS', 'BAN_MEMBERS'])
  .then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`))
  .catch(console.error);
// Remove all permissions from a role
role.setPermissions(0)
  .then(updated => console.log(`Updated permissions to ${updated.permissions.bitfield}`))
  .catch(console.error);

setPosition(position, optionsopt) → {Promise.<Role>}

Sets the position of the role.
Parameters:
Name Type Attributes Description
position number The position of the role
options Object <optional>
Options for setting position
Properties
Name Type Attributes Default Description
relative boolean <optional>
false Change the position relative to its current value
reason string <optional>
Reason for changing the position
Source:
Returns:
Type
Promise.<Role>
Example
// Set the position of the role
role.setPosition(1)
  .then(updated => console.log(`Role position: ${updated.position}`))
  .catch(console.error);

toString() → {string}

When concatenated with a string, this automatically returns the role's mention instead of the Role object.
Source:
Returns:
Type
string
Example
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);