ClientUser

export class ClientUser extends User
export class ClientUser extends User
Represents the logged in client's Discord user.

Extends

User
accentColor:number | null | undefined
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
Inherited from User
avatar:string | null
The user avatar's hash
Inherited from User
Deprecated
avatarDecoration:string | null
Use avatarDecorationData instead
Deprecated
The user avatar decoration's hash
Inherited from User
avatarDecorationData:AvatarDecorationData | null
The user avatar decoration's data
Inherited from User
Whether or not the user is a bot
Inherited from User
Readonly
client:Client<true>
The client that instantiated this
Inherited from Base
Readonly
createdAt:Date
The time the user was created at
Inherited from User
Readonly
createdTimestamp:number
The timestamp the user was created at
Inherited from User
Readonly
defaultAvatarURL:string
A link to the user's default avatar
Inherited from User
discriminator:string
The discriminator of this user '0', or a 4-digit stringified number if they're using the legacy username system
Inherited from User
Readonly
displayName:string
The global name of this user, or their username if they don't have one
Inherited from User
Readonly
dmChannel:DMChannel | null
The DM between the client's user and this user
Inherited from User
The flags for this user
Inherited from User
globalName:string | null
The global name of this user
Inherited from User
Readonly
hexAccentColor:HexColorString | null | undefined
The hexadecimal version of the user accent color, with a leading hash The user must be force fetched for this property to be present
Inherited from User
The user's id
Inherited from User
mfaEnabled:boolean
If the bot's Owner has MFA enabled on their account
Readonly
partial:false
Whether this User is a partial
Inherited from User
Readonly
Represents the client user's presence
system:boolean
Whether the user is an Official Discord System user (part of the urgent message system)
Inherited from User
Readonly
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
Inherited from User
username:string
The username of the user
Inherited from User
verified:boolean
Whether or not this account has been verified
avatarDecorationURL(options?):string | null
A link to the user's avatar decoration.
Returns
NameTypeOptionalDescription
optionsBaseImageURLOptionsYesOptions for the image URL
Inherited from User
avatarURL(options?):string | null
A link to the user's avatar.
Returns
NameTypeOptionalDescription
optionsImageURLOptionsYesOptions for the image URL
Inherited from User
bannerURL(options?):string | null | undefined
A link to the user's banner. See for more info
Returns
NameTypeOptionalDescription
optionsImageURLOptionsYesOptions for the image URL
Inherited from User
createDM(force?):Promise<DMChannel>
Creates a DM channel between the client and the user.
NameTypeOptionalDescription
forcebooleanYesWhether to skip the cache check and request the API
Inherited from User
deleteDM():Promise<DMChannel>
Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful.
Inherited from User
displayAvatarURL(options?):string
A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned.
NameTypeOptionalDescription
optionsImageURLOptionsYesOptions for the image URL
Inherited from User
edit(options):Promise<this>
Edits the logged in client.
NameTypeOptionalDescription
optionsClientUserEditOptionsNoThe options to provide
equals(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.
NameTypeOptionalDescription
userUserNoUser to compare with
Inherited from User
fetch(force?):Promise<User>
Fetches this user.
NameTypeOptionalDescription
forcebooleanYesWhether to skip the cache check and request the API
Inherited from User
fetchFlags(force?):Promise<UserFlagsBitField>
Fetches this user's flags.
NameTypeOptionalDescription
forcebooleanYesWhether to skip the cache check and request the API
Inherited from User
send(options):Promise<Message>
Sends a message to this user.
Example
// Send a direct message
user.send('Hello!')
.then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
.catch(console.error);
// Send a direct message
user.send('Hello!')
.then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
.catch(console.error);
NameTypeOptionalDescription
optionsstring | MessagePayload | MessageCreateOptionsNoThe options to provide
Inherited from User
setActivity(options?):ClientPresence
Sets the activity the client user is playing.
Example
// Set the client user's activity
client.user.setActivity('discord.js', { type: ActivityType.Watching });
// Set the client user's activity
client.user.setActivity('discord.js', { type: ActivityType.Watching });
NameTypeOptionalDescription
optionsActivityOptionsYesOptions for setting the activity
setAFK(afk?, shardId?):ClientPresence
Sets/removes the AFK flag for the client user.
NameTypeOptionalDescription
afkbooleanYesWhether or not the user is AFK
shardIdnumber | readonly number[]YesShard Id(s) to have the AFK flag set on
setAvatar(avatar):Promise<this>
Sets the avatar of the logged in client.
Example
// Set avatar
client.user.setAvatar('./avatar.png')
.then(user => console.log(`New avatar set!`))
.catch(console.error);
// Set avatar
client.user.setAvatar('./avatar.png')
.then(user => console.log(`New avatar set!`))
.catch(console.error);
NameTypeOptionalDescription
avatarBufferResolvable | Base64Resolvable | nullNoThe new avatar
setBanner(banner):Promise<this>
Sets the banner of the logged in client.
Example
// Set banner
client.user.setBanner('./banner.png')
.then(user => console.log(`New banner set!`))
.catch(console.error);
// Set banner
client.user.setBanner('./banner.png')
.then(user => console.log(`New banner set!`))
.catch(console.error);
NameTypeOptionalDescription
bannerBufferResolvable | Base64Resolvable | nullNoThe new banner
setPresence(data):ClientPresence
Sets the full presence of the client user.
Example
// Set the client user's presence
client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
// Set the client user's presence
client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });
NameTypeOptionalDescription
dataPresenceDataNoData for the presence
setStatus(status, shardId?):ClientPresence
Sets the status of the client user.
Example
// Set the client user's status
client.user.setStatus('idle');
// Set the client user's status
client.user.setStatus('idle');
NameTypeOptionalDescription
statusPresenceStatusDataNoStatus to change to
shardIdnumber | readonly number[]YesShard id(s) to have the activity set on
setUsername(username):Promise<this>
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!
Example
// Set username
client.user.setUsername('discordjs')
.then(user => console.log(`My new username is ${user.username}`))
.catch(console.error);
// Set username
client.user.setUsername('discordjs')
.then(user => console.log(`My new username is ${user.username}`))
.catch(console.error);
NameTypeOptionalDescription
usernamestringNoThe new username
toJSON(...props):unknown
NameTypeOptionalDescription
...propsRecord<string, boolean | string>[]NoNone
Inherited from Base
toString():UserMention
When concatenated with a string, this automatically returns the user's mention instead of the User object.
Example
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${user}!`);
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${user}!`);
Inherited from User
valueOf():string