class RoleManager

export class RoleManager extends CachedManager<Snowflake, Role, RoleResolvable>

Manages API methods for roles and stores their cache.

The role cache of this manager

readonly
client : Client

The client that instantiated this Manager

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() : Role | null

Gets the managed role a user created when joining the guild, if any Only ever available for bots

comparePositions() : 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

create() : 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.

Examples:
// 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);

delete(
reason?: string
) : Promise<void>

Deletes a role.

Examples:
// Delete a role
guild.roles.delete('222079219327434752', 'The role needed to go')
  .then(() => console.log('Deleted the role'))
  .catch(console.error);

edit() : Promise<Role>

Edits a role of the guild.

Examples:
// Edit a role
guild.roles.edit('222079219327434752', { name: 'buddies' })
  .then(updated => console.log(`Edited role name to ${updated.name}`))
  .catch(console.error);

fetch() : Promise<Role | null>

Obtains a role from Discord, or the role cache if they're already available.

Examples:
// 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);

resolve() : Role

Resolves a RoleResolvable to a Role object.

resolveId() : Snowflake

Resolves a RoleResolvable to a Role id.

setPosition() : Promise<Role>

Sets the new position of the role.

Examples:
// Set the position of the role
guild.roles.setPosition('222197033908436994', 1)
  .then(updated => console.log(`Role position: ${updated.position}`))
  .catch(console.error);

setPositions(
rolePositions: readonly RolePosition[]
) : Promise<Guild>

Batch-updates the guild's role positions

Examples:
guild.roles.setPositions([{ role: roleId, position: updatedRoleIndex }])
 .then(guild => console.log(`Role positions updated for ${guild}`))
 .catch(console.error);

valueOf() : Collection<Key, Holds>

Inherited from: DataManager