Skip to content

User

classe · Source

Represents a user on Discord.

Extends: BaseImplements: TextBasedChannel

Properties

id

id: Snowflake

The user's id Source

username

nullable

username: string

The username of the user Source

globalName

nullable

globalName: string

The global name of this user Source

bot

nullable

bot: boolean

Whether or not the user is a bot Source

discriminator

nullable

discriminator: string

The discriminator of this user '0', or a 4-digit stringified number if they're using the legacy username system Source

avatar

nullable

avatar: string

The user avatar's hash Source

nullable

banner: string

The user banner's hash The user must be force fetched for this property to be present or be updated Source

bannerColor

nullable

bannerColor: string

The user banner's hex The user must be force fetched for this property to be present or be updated Source

accentColor

nullable

accentColor: number

The base 10 accent color of the user's banner The user must be force fetched for this property to be present or be updated Source

system

nullable

system: boolean

Whether the user is an Official Discord System user (part of the urgent message system) Source

flags

nullable

flags: UserFlags

The flags for this user Source

avatarDecorationData

nullable

avatarDecorationData: AvatarDecorationData

The user avatar decoration's data Source

primaryGuild

nullable

primaryGuild: UserPrimaryGuild

The primary guild of the user Source

collectibles

nullable

collectibles: Collectibles

The user's collectibles Source

clan

nullable · deprecated

clan: PrimaryGuild

The primary clan the user is in Source

avatarDecoration

nullable · deprecated

avatarDecoration: string

The user avatar decoration's hash Source

partial

readonly

partial: boolean

Whether this User is a partial Source

createdTimestamp

readonly

createdTimestamp: number

The timestamp the user was created at Source

createdAt

readonly

createdAt: Date

The time the user was created at Source

defaultAvatarURL

readonly

defaultAvatarURL: string

A link to the user's default avatar Source

hexAccentColor

readonly · nullable

hexAccentColor: string

The hexadecimal version of the user accent color, with a leading hash The user must be force fetched for this property to be present Source

tag

readonly · nullable

tag: string

The tag of this user This user's username, or their legacy tag (e.g. hydrabolt#0001) if they're using the legacy username system Source

displayName

readonly · nullable

displayName: string

The global name of this user, or their username if they don't have one Source

dmChannel

readonly · nullable

dmChannel: DMChannel

The DM between the client's user and this user Source

note

nullable

note: string

The function returns the note associated with a specific client ID from a cache. Source

voice

readonly

voice: VoiceState

The voice state of this member Source

relationship

readonly

relationship: RelationshipType

Check relationship status (Client -> User) Source

friendNickname

readonly · nullable

friendNickname: string

Get friend nickname Source

client

readonly

client: Client

The client that instantiated this Source

Methods

avatarURL

avatarURL(options?: ImageURLOptions): string

A link to the user's avatar. Parameters

NameTypeDescription
options?ImageURLOptionsOptions for the Image URL Default: {}.

Returns: stringSource

avatarDecorationURL

avatarDecorationURL(): string

A link to the user's avatar decoration. Returns: stringSource

clanBadgeURL

deprecated

clanBadgeURL(): string

A link to the user's guild tag badge. Returns: stringSource

guildTagBadgeURL

guildTagBadgeURL(): string

A link to the user's guild tag badge. Returns: stringSource

displayAvatarURL

displayAvatarURL(options?: ImageURLOptions): string

A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned. Parameters

NameTypeDescription
options?ImageURLOptionsOptions for the Image URL Default: {}.

Returns: stringSource

bannerURL

bannerURL(options?: ImageURLOptions): string

A link to the user's banner. This method will throw an error if called before the user is force fetched. See User#banner for more info Parameters

NameTypeDescription
options?ImageURLOptionsOptions for the Image URL Default: {}.

Returns: stringSource

createDM

createDM(force?: boolean): Promise<DMChannel>

Creates a DM channel between the client and the user. Parameters

NameTypeDescription
force?booleanWhether to skip the cache check and request the API Default: false.

Returns: Promise<DMChannel>Source

deleteDM

deleteDM(): Promise<DMChannel>

Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful. Returns: Promise<DMChannel>Source

equals

equals(user: User): boolean

Checks if the user is equal to another. It compares id, username, discriminator, avatar, banner, accent color, and bot flags. It is recommended to compare equality by using user.id === user2.id unless you want to compare all properties. Parameters

NameTypeDescription
userUserUser to compare with

Returns: booleanSource

_equals

private

_equals(user: APIUser): boolean

Compares the user with an API user object Parameters

NameTypeDescription
userAPIUserThe API user object to compare

Returns: booleanSource

fetch

fetch(force?: boolean): Promise<User>

Fetches this user. Parameters

NameTypeDescription
force?booleanWhether to skip the cache check and request the API Default: true.

Returns: Promise<User>Source

getProfile

getProfile(guildId?: Snowflake): Promise<Object>

Returns a user profile object for a given user ID. This endpoint requires one of the following:

  • The user is a bot
  • The user shares a mutual guild with the current user
  • The user is a friend of the current user
  • The user is a friend suggestion of the current user
  • The user has an outgoing friend request to the current user Parameters
NameTypeDescription
guildId?SnowflakeThe guild ID to get the user's member profile in

Returns: Promise<Object>Source

toString

toString(): string

When concatenated with a string, this automatically returns the user's mention instead of the User object. Returns: string

js
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${user}!`);

Source

setNote

async

async setNote(note?: string | null | undefined): Promise<User>

The function updates the note of a user and returns the updated user. Parameters

NameTypeDescription
note?string | null | undefinedThe note parameter is the new value that you want to set for the note of the
user. It is an optional parameter and its default value is null. Default: null.

Returns: Promise<User> — The setNote method is returning the User object. Source

sendFriendRequest

sendFriendRequest(): Promise<boolean>

Send Friend Request to the user Returns: Promise<boolean>Source

deleteRelationship

deleteRelationship(): Promise<boolean>

Unblock / Unfriend / Cancels a friend request Returns: Promise<boolean>Source

send

send(options: string | MessagePayload | MessageOptions): Promise<Message>

Sends a message to this user. Parameters

NameTypeDescription
optionsstring | MessagePayload | MessageOptionsThe options to provide

Returns: Promise<Message>

js
// Send a direct message
user.send('Hello!')
  .then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
  .catch(console.error);

Source

Unofficial software. Not affiliated with or supported by Discord.