User

class User

A Discord account returned in an event payload or REST response. The object is a snapshot. Call User.fetch when current profile data matters.

Implements:

Properties

Property

Type

Description

accentColor

number | null | undefined

The user’s accent color as a 24-bit RGB integer, or null.

avatar

string | null | undefined

Hash of the user’s avatar, or null if using the default avatar.

banner

string | null | undefined

Hash of the user’s banner, or null if no banner is set.

bot

boolean | null | undefined

Indicates whether this user is a bot. undefined when omitted, null if Discord sent null.

createdAt

Date

When this Discord account was created, decoded from the user snowflake.

discriminator

string | undefined

The user’s four-digit discriminator (e.g. "1234"). undefined when omitted; not invented as "0".

displayName

string

The name best suited for display in user-facing output. Returns the global display name when set, otherwise the username.

globalName

string | null | undefined

The user’s global display name, or null if not set.

id

string

User ID.

primaryGuild

UserPrimaryGuild | null | undefined

The user’s displayed guild identity, or null when none is selected.

publicFlags

number | null | undefined

Public Discord user flags bitfield, or null when Discord omitted it.

username

string

The user’s display name (not globally unique).

Methods

User.displayAvatarURL(options: { format?: “png” | “jpg” | “webp” | “gif”; size?: number; }) → string

Get the CDN URL for the user’s avatar.

Parameters:
  • options: Optional size and image format for the avatar.

Returns:

The CDN URL string.

async User.fetch() → Promise<User>

Refetch the latest user data from Discord.

Returns:

The updated user object.

User.getTag() → string

Returns username#discriminator. For migrated accounts this is usually username#0.

Returns:

The tag string.

User.toMention() → string

Returns <@userId> mention syntax.

Returns:

The mention string for this user.