Skip to main content
Version: 0.8.0

Class: RoleManager

Extends​

  • BaseManager<string, Role>

Constructors​

Constructor​

new RoleManager(client, server, limit?): RoleManager

Manages API methods and caching for server roles.

Parameters​

ParameterTypeDefault value
clientClientundefined
serverServerundefined
limitnumberInfinity

Returns​

RoleManager

Overrides​

BaseManager<string, Role>.constructor

Properties​

cache​

cache: Collection<string, Role>

Inherited from​

BaseManager.cache


client​

client: Client

Inherited from​

BaseManager.client


server​

server: Server

Methods​

[custom]()​

[custom](): Collection<string, Role>

Returns​

Collection<string, Role>


construct()​

protected construct(data): Role

Tell BaseManager how to build a Role

Parameters​

ParameterType
data{ }

Returns​

Role

Overrides​

BaseManager.construct


create()​

create(options): Promise<Role>

Creates a new role in this server.

Parameters​

ParameterTypeDescription
optionsRoleCreateOptionsThe name and optional rank of the new role

Returns​

Promise<Role>

Role The role that was created

Throws​

If the role cannot be created (e.g., lack of permissions, invalid options).

Throws​

If invalid options are provided.

Example​

// Create a new role named "Moderator" with rank 1
const moderatorRole = await server.roles.create({ name: "Moderator", rank: 1 });
console.log(`Created role: ${moderatorRole.name} with ID: ${moderatorRole.id}`);

delete()​

delete(role): Promise<void>

Deletes a Role from the server.

Parameters​

ParameterTypeDescription
roleRoleResolvableThe RoleResolvable to delete

Returns​

Promise<void>

A promise that resolves when the role is successfully deleted.

Throws​

If an invalid RoleResolvable is provided.

Throws​

If the role cannot be deleted (e.g., lack of permissions).

Example​

// Delete a role by its ID
await server.roles.delete("01JE2MM759J5D7CHJF084R7MJ2");
console.log("Role deleted successfully.");

// Delete a role using a Role object
const role = await server.roles.fetch("01JE2MM759J5D7CHJF084R7");
await server.roles.delete(role);
console.log("Role deleted successfully.");

// Delete a role by mention
await server.roles.delete("<%01JE2MM759J5D7CHJF084R7MJ2>");
console.log("Role deleted successfully.");

edit()​

edit(role, options): Promise<Role>

Edits an existing role in the server.

Parameters​

ParameterTypeDescription
roleRoleResolvableThe RoleResolvable to edit.
optionsRoleEditOptionsThe fields to update.

Returns​

Promise<Role>

A promise that resolves to the updated Role.

Throws​

If invalid options or RoleResolvable are provided.

Throws​

If the API request fails (e.g., lack of permissions).

Example​

// Rename a role and give it a red color
await server.roles.edit("01H...", { name: "Super Admin", colour: "#FF0000" });

// Remove the custom color from a role
await server.roles.edit(role, { colour: null });

extractId()​

protected extractId(data): string

Tell BaseManager how to find the ID for Roles

Parameters​

ParameterType
data{ }

Returns​

string

Overrides​

BaseManager.extractId


fetch()​

fetch(role, force?): Promise<Role>

Fetches a Role from the API or resolves it from the local cache.

Parameters​

ParameterTypeDefault valueDescription
roleRoleResolvableundefinedThe ID, mention, or Role object to fetch.
forcebooleanfalseWhether to skip the cache check and force a direct API request. Defaults to false.

Returns​

Promise<Role>

A promise that resolves to the fetched Role object.

Throws​

If an invalid RoleResolvable is provided.

Throws​

If the API request fails (e.g., the role does not exist).

Example​

// Fetch a role from the API
const role = await server.roles.fetch("01JE2MM759J5D7CHJF084R7MJ2");
console.log(`Fetched role: ${role.name} with ID: ${role.id}`);

// Fetch a role by mention
const role = await.server.roles.fetch("<%01JE2MM759J5D7CHJF084R7MJ2>");
console.log(`Fetched role: ${role.name} with ID: ${role.id}`);

// Force fetch a role, bypassing the cache
const role = await server.roles.fetch("01JE2MM759J5D7CHJF084R7MJ2", true);
console.log(`Fetched role: ${role.name} with ID: ${role.id}`);

resolve()​

resolve(role): Role | undefined

Resolves a RoleResolvable to a Role object from the cache.

Parameters​

ParameterTypeDescription
roleRoleResolvableThe RoleResolvable to resolve.

Returns​

Role | undefined

The resolved Role object, or undefined if not found.


resolveId()​

resolveId(role): string

Extracts ID from a RoleResolvable.

Parameters​

ParameterTypeDescription
roleRoleResolvableThe RoleResolvable to extract the ID from.

Returns​

string

The extracted role ID.

Throws​

TypeError if an invalid type is provided.


setPermissions()​

setPermissions(role, options): Promise<Role>

Updates the permissions for a role in the server.

Parameters​

ParameterTypeDescription
roleRoleResolvableThe RoleResolvable to update permissions for.
optionsRolePermissionOptionsThe allow and deny permissions to set.

Returns​

Promise<Role>

A promise that resolves to the updated Role.

Throws​

If an invalid RoleResolvable or options are provided.

Throws​

If the API request fails.

Example​

// Set permissions using an array of strings.
await server.roles.setPermissions(role, {
allow: ["ManageChannel", "ViewChannel", "SendMessage"]
});

setRanks()​

setRanks(ranks): Promise<Server>

Updates the hierarchical positions of roles in the server.

Parameters​

ParameterTypeDescription
ranksRoleResolvable[]An array of RoleResolvables representing the new order of roles.

Returns​

Promise<Server>

A promise that resolves when the ranks are successfully updated.

Throws​

If the ranks parameter is not an array or contains invalid resolvables.

Throws​

If the API request fails.

Example​

// Reorder roles by passing an array of Role objects or IDs
await server.roles.setRanks(["RoleID_1", adminRoleObject, "RoleID_3"]);