class RoleManager
extends
CachedManager<Snowflake, Role, RoleResolvable>export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>
Manages API methods for roles and stores their cache.
readonlyCollection<Key, Holds> cache :
The cache of items for this manager.
Inherited from: DataManager
readonlyRole everyone :
The @everyone
role of the guild
Guild guild :
The guild belonging to this manager
readonlyRole highest :
The role with the highest position in the cache
readonlyConstructable<Holds> holds :
The data structure belonging to this manager.
Inherited from: DataManager
botRoleForuser: UserResolvable) : Role | null (
Gets the managed role a user created when joining the guild, if any Only ever available for bots
comparePositionsrole1: RoleResolvablerole2: RoleResolvable) : 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
createoptions?: RoleCreateOptions) : 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.
// Create a new role
guild.roles.create()
.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);
deleterole: RoleResolvablereason?: string) : Promise<void> (
Deletes a role.
// Delete a role
guild.roles.delete('222079219327434752', 'The role needed to go')
.then(() => console.log('Deleted the role'))
.catch(console.error);
editrole: RoleResolvableoptions: RoleEditOptions) : Promise<Role> (
Edits a role of the guild.
// Edit a role
guild.roles.edit('222079219327434752', { name: 'buddies' })
.then(updated => console.log(`Edited role name to ${updated.name}`))
.catch(console.error);
fetchid: Snowflakeoptions?: BaseFetchOptions) : Promise<Role | null> (
Obtains a role from Discord, or the role cache if they're already available.
// Fetch all roles from the guild
message.guild.roles.fetch()
.then(roles => console.log(`There are ${roles.size} roles.`))
.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);
resolverole: RoleResolvable) : Role (
Resolves a RoleResolvable to a Role object.
resolveIdrole: RoleResolvable) : Snowflake (
Resolves a RoleResolvable to a Role id.
Sets the new position of the role.
// Set the position of the role
guild.roles.setPosition('222197033908436994', 1)
.then(updated => console.log(`Role position: ${updated.position}`))
.catch(console.error);
setPositionsrolePositions: readonly RolePosition[]) : Promise<Guild> (
Batch-updates the guild's role positions
guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
.then(guild => console.log(`Role positions updated for ${guild}`))
.catch(console.error);
valueOfCollection<Key, Holds> () :
Inherited from: DataManager