Role

export class Role extends Base
export class Role extends Base
Represents a role on Discord.

Extends

Base
Readonly
client:Client<true>
The client that instantiated this
Inherited from Base
color:number
The base 10 color of the role
Readonly
createdAt:Date
The time the role was created at
Readonly
createdTimestamp:number
The timestamp the role was created at
Readonly
editable:boolean
Whether the role is editable by the client user
The flags of this role
guild:Guild
The guild that the role belongs to
Readonly
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
icon:string | null
The icon hash of the role
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
Readonly
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
The permissions of the role
Readonly
position:number
The position of the role in the role manager
rawPosition:number
The raw position of the role from the API
The tags this role has
unicodeEmoji:string | null
The unicode emoji for the role
comparePositionTo(role):number
Compares this role's position to another role's.
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
Example
// 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}`);
// 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}`);
NameTypeOptionalDescription
roleRoleResolvableNoRole to compare to this one
delete(reason?):Promise<Role>
Deletes the role.
Example
// Delete a role
role.delete('The role needed to go')
.then(deleted => console.log(`Deleted role ${deleted.name}`))
.catch(console.error);
// Delete a role
role.delete('The role needed to go')
.then(deleted => console.log(`Deleted role ${deleted.name}`))
.catch(console.error);
NameTypeOptionalDescription
reasonstringYesReason for deleting this role
edit(options):Promise<Role>
Edits the role.
Example
// Edit a role
role.edit({ name: 'new role' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
// Edit a role
role.edit({ name: 'new role' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
NameTypeOptionalDescription
optionsRoleEditOptionsNoThe options to provide
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.
NameTypeOptionalDescription
roleRoleNoRole to compare with
iconURL(options?):string | null
A link to the role's icon
Returns
NameTypeOptionalDescription
optionsImageURLOptionsYesOptions for the image URL
permissionsIn(channel, checkAdmin?):Readonly<PermissionsBitField>
Returns channel.permissionsFor(role). Returns permissions for a role in a guild channel, taking into account permission overwrites.
NameTypeOptionalDescription
channelNonThreadGuildBasedChannel | SnowflakeNoThe guild channel to use as context
checkAdminbooleanYesWhether having the PermissionFlagsBits.Administrator permission will return all permissions
setColor(color, reason?):Promise<Role>
Sets a new color for the 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);
// Set the color of a role
role.setColor('#FF0000')
.then(updated => console.log(`Set color of role to ${updated.color}`))
.catch(console.error);
NameTypeOptionalDescription
colorColorResolvableNoThe color of the role
reasonstringYesReason for changing the role's color
setHoist(hoist?, reason?):Promise<Role>
Sets whether or not the role should be hoisted.
Example
// Set the hoist of the role
role.setHoist(true)
.then(updated => console.log(`Role hoisted: ${updated.hoist}`))
.catch(console.error);
// Set the hoist of the role
role.setHoist(true)
.then(updated => console.log(`Role hoisted: ${updated.hoist}`))
.catch(console.error);
NameTypeOptionalDescription
hoistbooleanYesWhether or not to hoist the role
reasonstringYesReason for setting whether or not the role should be hoisted
setIcon(icon, reason?):Promise<Role>
Sets a new icon for the role.
NameTypeOptionalDescription
iconBufferResolvable | Base64Resolvable | EmojiResolvable | nullNoThe icon for the role The EmojiResolvable should belong to the same guild as the role. If not, pass the emoji's URL directly
reasonstringYesReason for changing the role's icon
setMentionable(mentionable?, reason?):Promise<Role>
Sets whether this role is mentionable.
Example
// Make the role mentionable
role.setMentionable(true)
.then(updated => console.log(`Role updated ${updated.name}`))
.catch(console.error);
// Make the role mentionable
role.setMentionable(true)
.then(updated => console.log(`Role updated ${updated.name}`))
.catch(console.error);
NameTypeOptionalDescription
mentionablebooleanYesWhether this role should be mentionable
reasonstringYesReason for setting whether or not this role should be mentionable
setName(name, reason?):Promise<Role>
Sets a new name for the role.
Example
// Set the name of the role
role.setName('new role')
.then(updated => console.log(`Updated role name to ${updated.name}`))
.catch(console.error);
// Set the name of the role
role.setName('new role')
.then(updated => console.log(`Updated role name to ${updated.name}`))
.catch(console.error);
NameTypeOptionalDescription
namestringNoThe new name of the role
reasonstringYesReason for changing the role's name
setPermissions(permissions, reason?):Promise<Role>
Sets the permissions of the role.
Example
// 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);
// 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);
Example
// Remove all permissions from a role
role.setPermissions(0n)
.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);
NameTypeOptionalDescription
permissionsPermissionResolvableNoThe permissions of the role
reasonstringYesReason for changing the role's permissions
setPosition(position, options?):Promise<Role>
Sets the new position of the role.
Example
// Set the position of the role
role.setPosition(1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
// Set the position of the role
role.setPosition(1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
NameTypeOptionalDescription
positionnumberNoThe new position for the role
optionsSetRolePositionOptionsYesOptions for setting the position
setUnicodeEmoji(unicodeEmoji, reason?):Promise<Role>
Sets a new unicode emoji for the role.
Example
// 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);
// 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);
NameTypeOptionalDescription
unicodeEmojistring | nullNoThe new unicode emoji for the role
reasonstringYesReason for changing the role's unicode emoji
toJSON():unknown
toString():RoleMention
When concatenated with a string, this automatically returns the role's mention instead of the Role object.
Example
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);
// Logs: Role: <@&123456789012345678>
console.log(`Role: ${role}`);
valueOf():string