User
classe · Source
Represents a user on Discord.
Extends: BaseImplements: TextBasedChannel
Properties
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
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);