Skip to main content
Version: 0.9.0

Class: UserManager

Extends​

  • BaseManager<string, User, RawUser>

Constructors​

Constructor​

new UserManager(client, limit?): UserManager

Parameters​

ParameterTypeDefault value
clientClientundefined
limitnumberInfinity

Returns​

UserManager

Overrides​

BaseManager<string, User, RawUser>.constructor

Properties​

cache​

cache: Collection<string, User>

Inherited from​

BaseManager.cache


client​

client: Client

Inherited from​

BaseManager.client

Methods​

construct()​

protected construct(data): User

Tell BaseManager how to build a User

Parameters​

ParameterType
data{ }

Returns​

User

Overrides​

BaseManager.construct


createDM()​

createDM(user, options?): Promise<DMChannel>

Creates a DM channel between the client's user and another user.

Parameters​

ParameterTypeDescription
userUserResolvableThe UserResolvable to create a DM with.
options{ force?: boolean; }Additional options for DM creation.
options.force?booleanIf true, forces the creation of a new DM channel even if one already exists.

Returns​

Promise<DMChannel>

A promise that resolves to the created DMChannel object.

Throws​

If an invalid UserResolvable is provided.

Throws​

If the API request fails.

Example​

// Create a DM with a user by ID
const dm = await client.users.createDM("1234567890");
console.log(`DM channel ID: ${dm.id}`);

editMe()​

editMe(options): Promise<User>

Edits the currently authenticated user (the bot itself).

Parameters​

ParameterTypeDescription
optionsUserEditOptionsThe fields to update (avatar, status, profile, etc.).

Returns​

Promise<User>

A promise that resolves to the updated User object.

Throws​

If invalid options are provided.

Throws​

If the API request fails.

Example​

// Update the bot's status and presence
await client.users.editMe({
status: { text: "Watching the server", presence: "Online" }
});

// Clear the bot's avatar and display name
await client.users.editMe({ avatar: null, displayName: null });

extractId()​

protected extractId(data): string

Tell BaseManager how to find the ID for Users

Parameters​

ParameterType
data{ }

Returns​

string

Overrides​

BaseManager.extractId


fetch()​

fetch(user, force?): Promise<User>

Fetches a User.

Parameters​

ParameterTypeDefault valueDescription
userUserResolvableundefinedThe ID or mention to fetch
forcebooleanfalseSkip the cache check and force an API request

Returns​

Promise<User>

The fetched User object

Throws​

Error if the user cannot be found or fetched

Throws​

TypeError if invalid UserResolvable is provided

Example​

// Fetch a user by ID
const user = await client.users.fetch("01JE2MM759J5D7CHJF084R7MJ2");
console.log(user.username);

// Fetch a user by mention
const user = await client.users.fetch("<@01JE2MM759J5D7CHJF084R7MJ2>");
console.log(user.username);

// Force fetch a user, bypassing the cache
const user = await client.users.fetch("01JE2MM759J5D7CHJF084R7MJ2", true);
console.log(user.username);

fetchMe()​

fetchMe(): Promise<User>

Fetch the current user (the bot itself).

Returns​

Promise<User>

The fetched User object representing the current user.

Throws​

Error if the user cannot be fetched.

Example​

// Fetch the current user (the bot itself)
const me = await client.users.fetchMe();
console.log(`Logged in as ${me.tag}`);

resolve()​

resolve(user): User | undefined

Resolves a UserResolvable to a User object from the cache.

Parameters​

ParameterType
userUserResolvable

Returns​

User | undefined


resolveId()​

resolveId(user): string

Extracts ID from a UserResolvable.

Parameters​

ParameterTypeDescription
userUserResolvableThe UserResolvable to extract the ID from.

Returns​

string

The extracted user ID.

Throws​

TypeError if an invalid type is provided.