RoleManager

export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
Manages API methods for roles and stores their cache.
Readonly
cache:Collection<Key, Holds>
The cache of items for this manager.
Inherited from DataManager
Readonly
client:Client
The client that instantiated this Manager
Inherited from BaseManager
Readonly
everyone:Role
The @everyone role of the guild
guild:Guild
The guild belonging to this manager
Readonly
highest:Role
The role with the highest position in the cache
Readonly
holds:Constructable<Holds>
The data structure belonging to this manager.
Inherited from DataManager
Readonly
premiumSubscriberRole:Role | null
The premium subscriber role of the guild, if any
botRoleFor(user):Role | null
Gets the managed role a user created when joining the guild, if any Only ever available for bots
Returns
NameTypeOptionalDescription
userUserResolvableNoThe user to access the bot role for
comparePositions(role1, role2):number
Compares the positions of two roles.
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
NameTypeOptionalDescription
role1RoleResolvableNoFirst role to compare
role2RoleResolvableNoSecond role to compare
create(options?):Promise<Role>
Creates a new role in the guild with given information. The position will silently reset to 1 if an invalid one is provided, or none.
Example
// Create a new role
guild.roles.create()
.then(console.log)
.catch(console.error);
// Create a new role
guild.roles.create()
.then(console.log)
.catch(console.error);
Example
// Create a new role with data and a reason
guild.roles.create({
name: 'Super Cool Blue People',
color: Colors.Blue,
reason: 'we needed a role for Super Cool People',
})
.then(console.log)
.catch(console.error);
// Create a new role with data and a reason
guild.roles.create({
name: 'Super Cool Blue People',
color: Colors.Blue,
reason: 'we needed a role for Super Cool People',
})
.then(console.log)
.catch(console.error);
NameTypeOptionalDescription
optionsRoleCreateOptionsYesOptions for creating the new role
delete(role, reason?):Promise<void>
Deletes a role.
Example
// Delete a role
guild.roles.delete('222079219327434752', 'The role needed to go')
.then(() => console.log('Deleted the role'))
.catch(console.error);
// Delete a role
guild.roles.delete('222079219327434752', 'The role needed to go')
.then(() => console.log('Deleted the role'))
.catch(console.error);
NameTypeOptionalDescription
roleRoleResolvableNoThe role to delete
reasonstringYesReason for deleting the role
edit(role, options):Promise<Role>
Edits a role of the guild.
Example
// Edit a role
guild.roles.edit('222079219327434752', { name: 'buddies' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
// Edit a role
guild.roles.edit('222079219327434752', { name: 'buddies' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
NameTypeOptionalDescription
roleRoleResolvableNoThe role to edit
optionsRoleEditOptionsNoThe options to provide
fetch(id, options?):Promise<Role | null>
Obtains a role from Discord, or the role cache if they're already available.
Example
// Fetch all roles from the guild
message.guild.roles.fetch()
.then(roles => console.log(`There are ${roles.size} roles.`))
.catch(console.error);
// Fetch all roles from the guild
message.guild.roles.fetch()
.then(roles => console.log(`There are ${roles.size} roles.`))
.catch(console.error);
Example
// Fetch a single role
message.guild.roles.fetch('222078108977594368')
.then(role => console.log(`The role color is: ${role.color}`))
.catch(console.error);
// Fetch a single role
message.guild.roles.fetch('222078108977594368')
.then(role => console.log(`The role color is: ${role.color}`))
.catch(console.error);
NameTypeOptionalDescription
idSnowflakeNoThe role's id
optionsBaseFetchOptionsYesAdditional options for this fetch
resolve(role):Role | null
Resolves a RoleResolvable to a Role object.
NameTypeOptionalDescription
roleRoleResolvableNoThe role resolvable to resolve
resolveId(role):Snowflake | null
Resolves a RoleResolvable to a Role id.
NameTypeOptionalDescription
roleRoleResolvableNoThe role resolvable to resolve
setPosition(role, position, options?):Promise<Role>
Sets the new position of the role.
Example
// Set the position of the role
guild.roles.setPosition('222197033908436994', 1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
// Set the position of the role
guild.roles.setPosition('222197033908436994', 1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
NameTypeOptionalDescription
roleRoleResolvableNoThe role to change the position of
positionnumberNoThe new position for the role
optionsSetRolePositionOptionsYesOptions for setting the position
setPositions(rolePositions):Promise<Guild>
Batch-updates the guild's role positions
Example
guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
.then(guild => console.log(`Role positions updated for ${guild}`))
.catch(console.error);
guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
.then(guild => console.log(`Role positions updated for ${guild}`))
.catch(console.error);
NameTypeOptionalDescription
rolePositionsreadonly RolePosition[]NoRole positions to update
valueOf():Collection<Key, Holds>