Constructor
new User(client, data)
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | The instantiating client |
data |
Object | The data for the user |
- Implements:
- Source:
Extends
Members
(nullable) avatar :string
The ID of the user's avatar
Type:
- string
- Source:
bot :boolean
Whether or not the user is a bot
Type:
- boolean
- Source:
(readonly) client :Client
The client that instantiated this
Type:
- Overrides:
- Source:
(readonly) createdAt :Date
The time the user was created at
Type:
- Date
- Source:
(readonly) createdTimestamp :number
The timestamp the user was created at
Type:
- number
- Source:
(readonly) defaultAvatarURL :string
A link to the user's default avatar
Type:
- string
- Source:
(nullable) discriminator :string
A discriminator based on username for the user
Type:
- string
- Source:
(readonly, nullable) dmChannel :DMChannel
The DM between the client's user and this user
Type:
- Source:
(nullable) flags :UserFlags
The flags for this user
Type:
- Source:
id :Snowflake
The ID of the user
Type:
- Source:
(readonly, nullable) lastMessage :Message
The Message object of the last message sent by the user, if one was sent
Type:
- Implements:
- Source:
(nullable) lastMessageChannelID :Snowflake
The ID of the channel for the last message sent by the user, if one was sent
Type:
- Source:
(nullable) lastMessageID :Snowflake
The ID of the last message sent by the user, if one was sent
Type:
- Source:
(nullable) locale :string
The locale of the user's client (ISO 639-1)
Type:
- string
- Source:
(readonly) partial :boolean
Whether this User is a partial
Type:
- boolean
- Source:
(readonly) presence :Presence
The presence of this user
Type:
- Source:
(nullable) system :boolean
Whether the user is an Official Discord System user (part of the urgent message system)
Type:
- boolean
- Source:
(readonly, nullable) tag :string
The Discord "tag" (e.g. `hydrabolt#0001`) for this user
Type:
- string
- Source:
(nullable) username :string
The username of the user
Type:
- string
- 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 |
- Source:
Returns:
- Type
- string
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 |
- Source:
Returns:
- Type
- Promise.<DMChannel>
deleteDM() → {Promise.<DMChannel>}
Deletes a DM channel (if one exists) between the client and the user. Resolves with the channel if successful.
- 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 |
- 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 |
- 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 |
- Source:
Returns:
- Type
- Promise.<User>
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 |
- Source:
Returns:
- Type
- Promise.<UserFlags>
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 |
- Implements:
- Source:
Returns:
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);
toString() → {string}
When concatenated with a string, this automatically returns the user's mention instead of the User object.
- 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 |
- 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 |
- 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 |
- Source:
Returns:
- Type
- Date