Class: ClientUser

ClientUser

Represents the logged in client's Discord user.

Constructor

new ClientUser()

Source:

Extends

Members

(nullable) avatar :string

The ID of the user's avatar
Type:
  • string
Overrides:
Source:

bot :boolean

Whether or not the user is a bot
Type:
  • boolean
Overrides:
Source:

(readonly) client :Client

The client that instantiated this
Type:
Overrides:
Source:

(readonly) createdAt :Date

The time the user was created at
Type:
  • Date
Overrides:
Source:

(readonly) createdTimestamp :number

The timestamp the user was created at
Type:
  • number
Overrides:
Source:

(readonly) defaultAvatarURL :string

A link to the user's default avatar
Type:
  • string
Overrides:
Source:

(nullable) discriminator :string

A discriminator based on username for the user
Type:
  • string
Overrides:
Source:

(readonly, nullable) dmChannel :DMChannel

The DM between the client's user and this user
Type:
Overrides:
Source:

(nullable) flags :UserFlags

The flags for this user
Type:
Overrides:
Source:

id :Snowflake

The ID of the user
Type:
Overrides:
Source:

(readonly, nullable) lastMessage :Message

The Message object of the last message sent by the user, if one was sent
Type:
Overrides:
Implements:
Source:

(nullable) lastMessageChannelID :Snowflake

The ID of the channel for the last message sent by the user, if one was sent
Type:
Overrides:
Source:

(nullable) lastMessageID :Snowflake

The ID of the last message sent by the user, if one was sent
Type:
Overrides:
Source:

(nullable) locale :string

The locale of the user's client (ISO 639-1)
Type:
  • string
Overrides:
Source:

(nullable) mfaEnabled :boolean

If the bot's Owner has MFA enabled on their account
Type:
  • boolean
Source:

(readonly) partial :boolean

Whether this User is a partial
Type:
  • boolean
Overrides:
Source:

(readonly) presence :Presence

ClientUser's presence
Type:
Overrides:
Source:

(nullable) system :boolean

Whether the user is an Official Discord System user (part of the urgent message system)
Type:
  • boolean
Overrides:
Source:

(readonly, nullable) tag :string

The Discord "tag" (e.g. `hydrabolt#0001`) for this user
Type:
  • string
Overrides:
Source:

(nullable) username :string

The username of the user
Type:
  • string
Overrides:
Source:

verified :boolean

Whether or not this account has been verified
Type:
  • boolean
Source:

Methods

avatarURL(optionsopt) → {string}

A link to the user's avatar.
Parameters:
Name Type Attributes Default Description
options ImageURLOptions <optional>
{} Options for the Image URL
Overrides:
Source:
Returns:
Type
string

(async) createDM(forceopt) → {Promise.<DMChannel>}

Creates a DM channel between the client and the user.
Parameters:
Name Type Attributes Default Description
force boolean <optional>
false Whether to skip the cache check and request the API
Overrides:
Source:
Returns:
Type
Promise.<DMChannel>

(async) deleteDM() → {Promise.<DMChannel>}

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

displayAvatarURL(optionsopt) → {string}

A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned.
Parameters:
Name Type Attributes Default Description
options ImageURLOptions <optional>
{} Options for the Image URL
Overrides:
Source:
Returns:
Type
string

equals(user) → {boolean}

Checks if the user is equal to another. It compares ID, username, discriminator, avatar, and bot flags. It is recommended to compare equality by using `user.id === user2.id` unless you want to compare all properties.
Parameters:
Name Type Description
user User User to compare with
Overrides:
Source:
Returns:
Type
boolean

fetch(forceopt) → {Promise.<User>}

Fetches this user.
Parameters:
Name Type Attributes Default Description
force boolean <optional>
false Whether to skip the cache check and request the AP
Overrides:
Source:
Returns:
Type
Promise.<User>

(async) fetchFlags(forceopt) → {Promise.<UserFlags>}

Fetches this user's flags.
Parameters:
Name Type Attributes Default Description
force boolean <optional>
false Whether to skip the cache check and request the AP
Overrides:
Source:
Returns:
Type
Promise.<UserFlags>

(async) send(contentopt, optionsopt) → {Promise.<(Message|Array.<Message>)>}

Sends a message to this channel.
Parameters:
Name Type Attributes Default Description
content StringResolvable | APIMessage <optional>
'' The content to send
options MessageOptions | MessageAdditions <optional>
{} The options to provide
Overrides:
Implements:
Source:
Returns:
Type
Promise.<(Message|Array.<Message>)>
Examples
// Send a basic message
channel.send('hello!')
  .then(message => console.log(`Sent message: ${message.content}`))
  .catch(console.error);
// Send a remote file
channel.send({
  files: ['https://cdn.discordapp.com/icons/222078108977594368/6e1019b3179d71046e463a75915e7244.png?size=2048']
})
  .then(console.log)
  .catch(console.error);
// Send a local file
channel.send({
  files: [{
    attachment: 'entire/path/to/file.jpg',
    name: 'file.jpg'
  }]
})
  .then(console.log)
  .catch(console.error);
// Send an embed with a local image inside
channel.send('This is an embed', {
  embed: {
    thumbnail: {
         url: 'attachment://file.jpg'
      }
   },
   files: [{
      attachment: 'entire/path/to/file.jpg',
      name: 'file.jpg'
   }]
})
  .then(console.log)
  .catch(console.error);

setActivity(nameopt, optionsopt) → {Promise.<Presence>}

Sets the activity the client user is playing.
Parameters:
Name Type Attributes Description
name string | ActivityOptions <optional>
Activity being played, or options for setting the activity
options ActivityOptions <optional>
Options for setting the activity
Source:
Returns:
Type
Promise.<Presence>
Example
// Set the client user's activity
client.user.setActivity('discord.js', { type: 'WATCHING' })
  .then(presence => console.log(`Activity set to ${presence.activities[0].name}`))
  .catch(console.error);

setAFK(afk) → {Promise.<Presence>}

Sets/removes the AFK flag for the client user.
Parameters:
Name Type Description
afk boolean Whether or not the user is AFK
Source:
Returns:
Type
Promise.<Presence>

(async) setAvatar(avatar) → {Promise.<ClientUser>}

Sets the avatar of the logged in client.
Parameters:
Name Type Description
avatar BufferResolvable | Base64Resolvable The new avatar
Source:
Returns:
Type
Promise.<ClientUser>
Example
// Set avatar
client.user.setAvatar('./avatar.png')
  .then(user => console.log(`New avatar set!`))
  .catch(console.error);

setPresence(data) → {Promise.<Presence>}

Sets the full presence of the client user.
Parameters:
Name Type Description
data PresenceData Data for the presence
Source:
Returns:
Type
Promise.<Presence>
Example
// Set the client user's presence
client.user.setPresence({ activity: { name: 'with discord.js' }, status: 'idle' })
  .then(console.log)
  .catch(console.error);

setStatus(status, shardIDopt) → {Promise.<Presence>}

Sets the status of the client user.
Parameters:
Name Type Attributes Description
status PresenceStatusData Status to change to
shardID number | Array.<number> <optional>
Shard ID(s) to have the activity set on
Source:
Returns:
Type
Promise.<Presence>
Example
// Set the client user's status
client.user.setStatus('idle')
  .then(console.log)
  .catch(console.error);

setUsername(username) → {Promise.<ClientUser>}

Sets the username of the logged in client. Changing usernames in Discord is heavily rate limited, with only 2 requests every hour. Use this sparingly!
Parameters:
Name Type Description
username string The new username
Source:
Returns:
Type
Promise.<ClientUser>
Example
// Set username
client.user.setUsername('discordjs')
  .then(user => console.log(`My new username is ${user.username}`))
  .catch(console.error);

toString() → {string}

When concatenated with a string, this automatically returns the user's mention instead of the User object.
Overrides:
Source:
Returns:
Type
string
Example
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${user}!`);

typingDurationIn(channel) → {number}

Gets the amount of time the user has been typing in a channel for (in milliseconds), or -1 if they're not typing.
Parameters:
Name Type Description
channel ChannelResolvable The channel to get the time in
Overrides:
Source:
Returns:
Type
number

typingIn(channel) → {boolean}

Checks whether the user is typing in a channel.
Parameters:
Name Type Description
channel ChannelResolvable The channel to check in
Overrides:
Source:
Returns:
Type
boolean

typingSinceIn(channel) → {Date}

Gets the time that the user started typing.
Parameters:
Name Type Description
channel ChannelResolvable The channel to get the time in
Overrides:
Source:
Returns:
Type
Date