ClientUser
classe · Source
Represents the logged in client's Discord user.
Extends: User
Properties
verified
Whether or not this account has been verified Source
mfaEnabled
If the bot's Owner has MFA enabled on their account Source
purchasedFlags
Purchased state of the client user. Source
premiumUsageFlags
Premium usage state of the client user. Source
phone
Phone number of the client user. Source
nsfwAllowed
Whether or not the client user is allowed to send NSFW messages [iOS device]. Source
email
Email address of the client user. Source
bio
About me (User) The user must be force fetched for this property to be present or be updated Source
pronouns
Pronouns (User) The user must be force fetched for this property to be present or be updated Source
premiumType
Premium types denote the level of premium a user has. Source
presence
Represents the client user's presence Source
id
The user's id Source
username
The username of the user Source
globalName
The global name of this user Source
bot
Whether or not the user is a bot Source
discriminator
The discriminator of this user '0', or a 4-digit stringified number if they're using the legacy username system Source
avatar
The user avatar's hash Source
banner
The user banner's hash The user must be force fetched for this property to be present or be updated Source
bannerColor
The user banner's hex The user must be force fetched for this property to be present or be updated Source
accentColor
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
Whether the user is an Official Discord System user (part of the urgent message system) Source
flags
The flags for this user Source
avatarDecorationData
The user avatar decoration's data Source
primaryGuild
The primary guild of the user Source
collectibles
The user's collectibles Source
clan
The primary clan the user is in Source
avatarDecoration
The user avatar decoration's hash Source
partial
Whether this User is a partial Source
createdTimestamp
The timestamp the user was created at Source
createdAt
The time the user was created at Source
defaultAvatarURL
A link to the user's default avatar Source
hexAccentColor
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
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
The global name of this user, or their username if they don't have one Source
dmChannel
The DM between the client's user and this user Source
note
The function returns the note associated with a specific client ID from a cache. Source
voice
The voice state of this member Source
relationship
Check relationship status (Client -> User) Source
friendNickname
Get friend nickname Source
client
The client that instantiated this Source
Methods
edit
Edits the logged in client. Parameters
| Name | Type | Description |
|---|---|---|
options | ClientUserEditData | The new data |
Returns: Promise<ClientUser>Source
setUsername
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 |
password | string | Current Password |
Returns: Promise<ClientUser>
// Set username
client.user.setUsername('discordjs', 'passw@rd')
.then(user => console.log(`My new username is ${user.username}`))
.catch(console.error);setAvatar
Sets the avatar of the logged in client. Parameters
| Name | Type | Description |
|---|---|---|
avatar | BufferResolvable | Base64Resolvable | The new avatar |
Returns: Promise<ClientUser>
// Set avatar
client.user.setAvatar('./avatar.png')
.then(user => console.log(`New avatar set!`))
.catch(console.error);setPresence
Sets the full presence of the client user. Parameters
| Name | Type | Description |
|---|---|---|
data | PresenceData | Data for the presence |
Returns: ClientPresence
// Set the client user's presence
client.user.setPresence({ activities: [{ name: 'with discord.js' }], status: 'idle' });setStatus
Sets the status of the client user. Parameters
| Name | Type | Description |
|---|---|---|
status | PresenceStatusData | Status to change to |
shardId? | number | Array<number> | Shard id(s) to have the activity set on |
Returns: ClientPresence
// Set the client user's status
client.user.setStatus('idle');setActivity
Sets the activity the client user is playing. Parameters
| Name | Type | Description |
|---|---|---|
name | string | ActivityOptions | Activity being played, or options for setting the activity |
options? | ActivityOptions | Options for setting the activity |
Returns: ClientPresence
// Set the client user's activity
client.user.setActivity('discord.js', { type: 'WATCHING' });setAFK
Sets/removes the AFK flag for the client user. Parameters
| Name | Type | Description |
|---|---|---|
afk? | boolean | Whether or not the user is AFK Default: true. |
shardId? | number | Array<number> | Shard Id(s) to have the AFK flag set on |
Returns: ClientPresenceSource
setBanner
Sets the banner of the logged in client. Parameters
| Name | Type | Description |
|---|---|---|
banner | BufferResolvable | Base64Resolvable | The new banner |
Returns: Promise<ClientUser>
// Set banner
client.user.setBanner('./banner.png')
.then(user => console.log(`New banner set!`))
.catch(console.error);setHypeSquad
Set HyperSquad House Parameters
| Name | Type | Description |
|---|---|---|
type | string | number | * LEAVE: 0* HOUSE_BRAVERY: 1* HOUSE_BRILLIANCE: 2* HOUSE_BALANCE: 3 |
Returns: Promise<void>
// Set HyperSquad HOUSE_BRAVERY
client.user.setHypeSquad(1); || client.user.setHypeSquad('HOUSE_BRAVERY');
// Leave
client.user.setHypeSquad(0);setAccentColor
Set Accent color Parameters
| Name | Type | Description |
|---|---|---|
color | ColorResolvable | Color to set Default: null. |
Returns: Promise<ClientUser>Source
setAboutMe
Set About me Parameters
| Name | Type | Description |
|---|---|---|
bio? | string | Bio to set Default: null. |
Returns: Promise<ClientUser>Source
createFriendInvite
Create an invite [Friend Invites] maxAge: 604800 | maxUses: 1 Returns: Promise<Invite>
// Options not working
client.user.createFriendInvite();
.then(console.log)
.catch(console.error);getAllFriendInvites
Get all friend invites Returns: Promise<Collection<string, Invite>>Source
revokeAllFriendInvites
Revoke all friend invites Returns: Promise<void>Source
setSamsungActivity
Sets Discord Playing status to "Playing on Samsung Galaxy". Only selected gamss from discords database works Parameters
| Name | Type | Description |
|---|---|---|
packageName | string | Android package name |
type | string | Must be START, UPDATE, or STOP Default: START. |
Returns: Promise<ClientUser>
// Set the client user's status
client.user.setSamsungActivity('com.YostarJP.BlueArchive', 'START');
// Update
client.user.setSamsungActivity('com.miHoYo.bh3oversea', 'UPDATE');
// Stop
client.user.setSamsungActivity('com.miHoYo.GenshinImpact', 'STOP');stopRinging
Stop ringing Parameters
| Name | Type | Description |
|---|---|---|
channel | ChannelResolvable | DMChannel |
Returns: Promise<void>Source
fetchBurstCredit
Super Reactions Returns: Promise<number>Source
setGlobalName
Set global display name Parameters
| Name | Type | Description |
|---|---|---|
globalName | string | The new display name |
Returns: Promise<ClientUser>Source
setPronouns
Set pronouns Parameters
| Name | Type | Description |
|---|---|---|
pronouns | string | Your pronouns |
Returns: Promise<ClientUser>Source
avatarURL
A link to the user's avatar. Parameters
| Name | Type | Description |
|---|---|---|
options? | ImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
avatarDecorationURL
A link to the user's avatar decoration. Returns: stringSource
clanBadgeURL
A link to the user's guild tag badge. Returns: stringSource
guildTagBadgeURL
A link to the user's guild tag badge. Returns: stringSource
displayAvatarURL
A link to the user's avatar if they have one. Otherwise a link to their default avatar will be returned. Parameters
| Name | Type | Description |
|---|---|---|
options? | ImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
bannerURL
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
| Name | Type | Description |
|---|---|---|
options? | ImageURLOptions | Options for the Image URL Default: {}. |
Returns: stringSource
createDM
Creates a DM channel between the client and the user. Parameters
| Name | Type | Description |
|---|---|---|
force? | boolean | Whether to skip the cache check and request the API Default: false. |
Returns: Promise<DMChannel>Source
deleteDM
Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful. Returns: Promise<DMChannel>Source
equals
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
| Name | Type | Description |
|---|---|---|
user | User | User to compare with |
Returns: booleanSource
_equals
Compares the user with an API user object Parameters
| Name | Type | Description |
|---|---|---|
user | APIUser | The API user object to compare |
Returns: booleanSource
fetch
Fetches this user. Parameters
| Name | Type | Description |
|---|---|---|
force? | boolean | Whether to skip the cache check and request the API Default: true. |
Returns: Promise<User>Source
getProfile
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
| Name | Type | Description |
|---|---|---|
guildId? | Snowflake | The guild ID to get the user's member profile in |
Returns: Promise<Object>Source
toString
When concatenated with a string, this automatically returns the user's mention instead of the User object. Returns: string
// Logs: Hello from <@123456789012345678>!
console.log(`Hello from ${user}!`);setNote
The function updates the note of a user and returns the updated user. Parameters
| Name | Type | Description |
|---|---|---|
note? | string | null | undefined | The note parameter is the new value that you want to set for the note of theuser. 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
Send Friend Request to the user Returns: Promise<boolean>Source
deleteRelationship
Unblock / Unfriend / Cancels a friend request Returns: Promise<boolean>Source
send
Sends a message to this user. Parameters
| Name | Type | Description |
|---|---|---|
options | string | MessagePayload | MessageOptions | The options to provide |
Returns: Promise<Message>
// Send a direct message
user.send('Hello!')
.then(message => console.log(`Sent message: ${message.content} to ${user.tag}`))
.catch(console.error);