Constructor
new Message(client, data, channel)
Parameters:
Name | Type | Description |
---|---|---|
client |
Client | The instantiating client |
data |
Object | The data for the message |
channel |
TextChannel | DMChannel | NewsChannel | The channel the message was sent in |
- Source:
Extends
Members
(private) _edits :Array.<Message>
The previous versions of the message, sorted with the most recent first
Type:
- Array.<Message>
- Source:
(nullable) activity :MessageActivity
Group activity
Type:
- Source:
(nullable) application :ClientApplication
Supplemental application information for group activities
Type:
- Source:
attachments :Collection.<Snowflake, MessageAttachment>
A collection of attachments in the message - e.g. Pictures - mapped by their ID
Type:
- Collection.<Snowflake, MessageAttachment>
- Source:
(nullable) author :User
The author of the message
Type:
- Source:
channel :TextChannel|DMChannel|NewsChannel
The channel that the message was sent in
Type:
- Source:
(readonly) cleanContent :string
The message contents with all mentions replaced by the equivalent text.
If mentions cannot be resolved to a name, the relevant mention in the message content will not be converted.
Type:
- string
- Source:
(readonly) client :Client
The client that instantiated this
Type:
- Overrides:
- Source:
(nullable) content :string
The content of the message
Type:
- string
- Source:
(readonly) createdAt :Date
The time the message was sent at
Type:
- Date
- Source:
createdTimestamp :number
The timestamp the message was sent at
Type:
- number
- Source:
(readonly) deletable :boolean
Whether the message is deletable by the client user
Type:
- boolean
- Source:
deleted :boolean
Whether this message has been deleted
Type:
- boolean
- Source:
(readonly) editable :boolean
Whether the message is editable by the client user
Type:
- boolean
- Source:
(readonly, nullable) editedAt :Date
The time the message was last edited at (if applicable)
Type:
- Date
- Source:
(nullable) editedTimestamp :number
The timestamp the message was last edited at (if applicable)
Type:
- number
- Source:
(readonly) edits :Array.<Message>
An array of cached versions of the message, including the current version
Sorted from latest (first) to oldest (last)
Type:
- Array.<Message>
- Source:
embeds :Array.<MessageEmbed>
A list of embeds in the message - e.g. YouTube Player
Type:
- Array.<MessageEmbed>
- Source:
flags :Readonly.<MessageFlags>
Flags that are applied to the message
Type:
- Readonly.<MessageFlags>
- Source:
(readonly, nullable) guild :Guild
The guild the message was sent in (if in a guild channel)
Type:
- Source:
id :Snowflake
The ID of the message
Type:
- Source:
(readonly, nullable) member :GuildMember
Represents the author of the message as a guild member.
Only available if the message comes from a guild where the author is still a member
Type:
- Source:
mentions :MessageMentions
All valid mentions that the message contains
Type:
- Source:
(nullable) nonce :string
A random number or string used for checking message delivery
This is only received after the message was sent successfully, and
lost if re-fetched
Type:
- string
- Source:
(readonly) partial :boolean
Whether or not this message is a partial
Type:
- boolean
- Source:
(readonly) pinnable :boolean
Whether the message is pinnable by the client user
Type:
- boolean
- Source:
(nullable) pinned :boolean
Whether or not this message is pinned
Type:
- boolean
- Source:
reactions :ReactionManager
A manager of the reactions belonging to this message
Type:
- Source:
(nullable) reference :MessageReference
Message reference data
Type:
- Source:
(nullable) system :boolean
Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications)
Type:
- boolean
- Source:
(nullable) tts :boolean
Whether or not the message was Text-To-Speech
Type:
- boolean
- Source:
(nullable) type :MessageType
The type of the message
Type:
- Source:
(readonly) url :string
The url to jump to this message
Type:
- string
- Source:
(nullable) webhookID :Snowflake
ID of the webhook that sent the message, if applicable
Type:
- Source:
Methods
awaitReactions(filter, optionsopt) → {Promise.<Collection.<string, MessageReaction>>}
Similar to createReactionCollector but in promise form.
Resolves with a collection of reactions that pass the specified filter.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
filter |
CollectorFilter | The filter function to use | ||
options |
AwaitReactionsOptions |
<optional> |
{} | Optional options to pass to the internal collector |
- Source:
Returns:
- Type
- Promise.<Collection.<string, MessageReaction>>
Example
// Create a reaction collector
const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID'
message.awaitReactions(filter, { time: 15000 })
.then(collected => console.log(`Collected ${collected.size} reactions`))
.catch(console.error);
createReactionCollector(filter, optionsopt) → {ReactionCollector}
Creates a reaction collector.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
filter |
CollectorFilter | The filter to apply | ||
options |
ReactionCollectorOptions |
<optional> |
{} | Options to send to the collector |
- Source:
Returns:
- Type
- ReactionCollector
Example
// Create a reaction collector
const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someID';
const collector = message.createReactionCollector(filter, { time: 15000 });
collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
delete(optionsopt) → {Promise.<Message>}
Deletes the message.
Parameters:
Name | Type | Attributes | Description | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Options
Properties
|
- Source:
Returns:
- Type
- Promise.<Message>
Example
// Delete a message
message.delete({ timeout: 5000 })
.then(msg => console.log(`Deleted message from ${msg.author.username} after 5 seconds`))
.catch(console.error);
edit(contentopt, optionsopt) → {Promise.<Message>}
Edits the content of the message.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
content |
StringResolvable | APIMessage |
<optional> |
The new content for the message |
options |
MessageEditOptions | MessageEmbed |
<optional> |
The options to provide |
- Source:
Returns:
- Type
- Promise.<Message>
Example
// Update the content of a message
message.edit('This is my new content!')
.then(msg => console.log(`Updated the content of a message to ${msg.content}`))
.catch(console.error);
equals(message, rawData) → {boolean}
Used mainly internally. Whether two messages are identical in properties. If you want to compare messages
without checking all the properties, use `message.id === message2.id`, which is much more efficient. This
method allows you to see if there are differences in content, embeds, attachments, nonce and tts properties.
Parameters:
Name | Type | Description |
---|---|---|
message |
Message | The message to compare it to |
rawData |
Object | Raw data passed through the WebSocket about this message |
- Source:
Returns:
- Type
- boolean
fetch(forceopt) → {Promise.<Message>}
Fetch this message.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
force |
boolean |
<optional> |
false | Whether to skip the cache check and request the API |
- Source:
Returns:
- Type
- Promise.<Message>
fetchWebhook() → {Promise.<?Webhook>}
Fetches the webhook used to create this message.
- Source:
Returns:
- Type
- Promise.<?Webhook>
(private) patch(data)
Updates the message.
Parameters:
Name | Type | Description |
---|---|---|
data |
Object | Raw Discord message update data |
- Source:
pin(optionsopt) → {Promise.<Message>}
Pins this message to the channel's pinned messages.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Options for pinning
Properties
|
- Source:
Returns:
- Type
- Promise.<Message>
Example
// Pin a message with a reason
message.pin({ reason: 'important' })
.then(console.log)
.catch(console.error)
react(emoji) → {Promise.<MessageReaction>}
Adds a reaction to the message.
Parameters:
Name | Type | Description |
---|---|---|
emoji |
EmojiIdentifierResolvable | The emoji to react with |
- Source:
Returns:
- Type
- Promise.<MessageReaction>
Examples
// React to a message with a unicode emoji
message.react('🤔')
.then(console.log)
.catch(console.error);
// React to a message with a custom emoji
message.react(message.guild.emojis.cache.get('123456789012345678'))
.then(console.log)
.catch(console.error);
reply(contentopt, optionsopt) → {Promise.<(Message|Array.<Message>)>}
Replies to the message.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
content |
StringResolvable | APIMessage |
<optional> |
'' | The content for the message |
options |
MessageOptions | MessageAdditions |
<optional> |
{} | The options to provide |
- Source:
Returns:
Example
// Reply to a message
message.reply('Hey, I\'m a reply!')
.then(() => console.log(`Sent a reply to ${message.author.username}`))
.catch(console.error);
suppressEmbeds(suppressopt) → {Promise.<Message>}
Suppresses or unsuppresses embeds on a message
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
suppress |
boolean |
<optional> |
true | If the embeds should be suppressed or not |
- Source:
Returns:
- Type
- Promise.<Message>
toString() → {string}
When concatenated with a string, this automatically concatenates the message's content instead of the object.
- Source:
Returns:
- Type
- string
Example
// Logs: Message: This is a message!
console.log(`Message: ${message}`);
unpin(optionsopt) → {Promise.<Message>}
Unpins this message from the channel's pinned messages.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Options for unpinning
Properties
|
- Source:
Returns:
- Type
- Promise.<Message>
Example
// Unpin a message with a reason
message.unpin({ reason: 'no longer relevant' })
.then(console.log)
.catch(console.error)