Message
classe · Source
Represents a message on Discord.
Extends: Base
Properties
channelId
The id of the channel the message was sent in Source
guildId
nullable
The id of the guild the message was sent in, if any Source
id
The message's id Source
position
nullable
A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread. Source
createdTimestamp
The timestamp the message was sent at Source
type
nullable
The type of the message Source
system
nullable
Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications) Source
content
nullable
The content of the message Source
author
nullable
The author of the message Source
pinned
nullable
Whether or not this message is pinned Source
tts
nullable
Whether or not the message was Text-To-Speech Source
nonce
nullable
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 Source
embeds
A list of embeds in the message - e.g. YouTube Player Source
components
An array of components in the message Source
attachments
A collection of attachments in the message - e.g. Pictures - mapped by their ids Source
stickers
A collection of stickers in the message Source
editedTimestamp
nullable
The timestamp the message was last edited at (if applicable) Source
reactions
A manager of the reactions belonging to this message Source
mentions
All valid mentions that the message contains Source
webhookId
nullable
The id of the webhook that sent the message, if applicable Source
poll
nullable
The poll that was sent with the message Source
groupActivityApplication
nullable
Supplemental application information for group activities Source
applicationId
nullable
The id of the application of the interaction that sent this message, if any Source
activity
nullable
Group activity Source
flags
Flags that are applied to the message Source
reference
nullable
Message reference data Source
interaction
nullable
Partial data of the interaction that this message is a reply to Source
messageSnapshots
The message snapshots associated with the message reference Source
call
nullable
The call associated with the message Source
deleted
deprecated
Whether or not the structure has been deleted Source
channel
readonly
The channel that the message was sent in Source
partial
readonly
Whether or not this message is a partial Source
member
readonly · nullable
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 Source
createdAt
readonly
The time the message was sent at Source
editedAt
readonly · nullable
The time the message was last edited at (if applicable) Source
guild
readonly · nullable
The guild the message was sent in (if in a guild channel) Source
hasThread
readonly
Whether this message has a thread associated with it Source
thread
readonly · nullable
The thread started by this message This property is not suitable for checking whether a message has a thread, use Message#hasThread instead. Source
url
readonly
The URL to jump to this message Source
cleanContent
readonly · nullable
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. Source
editable
readonly
Whether the message is editable by the client user Source
deletable
readonly
Whether the message is deletable by the client user Source
bulkDeletable
readonly
Whether the message is bulk deletable by the client user Source
pinnable
readonly
Whether the message is pinnable by the client user Source
crosspostable
readonly
Whether the message is crosspostable by the client user Source
isMessage
readonly
Check data Source
client
readonly
The client that instantiated this Source
Methods
createReactionCollector
Creates a reaction collector. Parameters
| Name | Type | Description |
|---|---|---|
options? | ReactionCollectorOptions | Options to send to the collector Default: {}. |
Returns: ReactionCollector
// Create a reaction collector
const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId';
const collector = message.createReactionCollector({ filter, time: 15_000 });
collector.on('collect', r => console.log(`Collected ${r.emoji.name}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));2
3
4
5
awaitReactions
Similar to createReactionCollector but in promise form. Resolves with a collection of reactions that pass the specified filter. Parameters
| Name | Type | Description |
|---|---|---|
options? | AwaitReactionsOptions | Optional options to pass to the internal collector Default: {}. |
Returns: Promise<Collection<(string\|Snowflake), MessageReaction>>
// Create a reaction collector
const filter = (reaction, user) => reaction.emoji.name === '👌' && user.id === 'someId'
message.awaitReactions({ filter, time: 15_000 })
.then(collected => console.log(`Collected ${collected.size} reactions`))
.catch(console.error);2
3
4
5
fetchReference
async
Fetches the Message this crosspost/reply/pin-add references, if available to the client Returns: Promise<Message>Source
edit
async
Edits the content of the message. Parameters
| Name | Type | Description |
|---|---|---|
options | string | MessagePayload | MessageEditOptions | The options to provide |
Returns: Promise<Message>
// 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);2
3
4
crosspost
async
Publishes a message in an announcement channel to all channels following it. Returns: Promise<Message>
// Crosspost a message
if (message.channel.type === 'GUILD_NEWS') {
message.crosspost()
.then(() => console.log('Crossposted message'))
.catch(console.error);
}2
3
4
5
6
pin
async
Pins this message to the channel's pinned messages. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for pinning |
Returns: Promise<Message>
// Pin a message
message.pin()
.then(console.log)
.catch(console.error)2
3
4
unpin
async
Unpins this message from the channel's pinned messages. Parameters
| Name | Type | Description |
|---|---|---|
reason? | string | Reason for unpinning |
Returns: Promise<Message>
// Unpin a message
message.unpin()
.then(console.log)
.catch(console.error)2
3
4
react
async
Adds a reaction to the message. Parameters
| Name | Type | Description |
|---|---|---|
emoji | EmojiIdentifierResolvable | The emoji to react with |
burst? | boolean | Super Reactions Default: false. |
Returns: Promise<MessageReaction>
// React to a message with a unicode emoji
message.react('🤔')
.then(console.log)
.catch(console.error);2
3
4
// React to a message with a custom emoji
message.react(message.guild.emojis.cache.get('123456789012345678'))
.then(console.log)
.catch(console.error);2
3
4
delete
async
Deletes the message. Returns: Promise<Message>
// Delete a message
message.delete()
.then(msg => console.log(`Deleted message from ${msg.author.username}`))
.catch(console.error);2
3
4
reply
async
Send an inline reply to this message. Parameters
| Name | Type | Description |
|---|---|---|
options | string | MessagePayload | ReplyMessageOptions | The options to provide |
Returns: Promise<Message>
// Reply to a message
message.reply('This is a reply!')
.then(() => console.log(`Replied to message "${message.content}"`))
.catch(console.error);2
3
4
forward
Forwards this message Parameters
| Name | Type | Description |
|---|---|---|
channel | TextBasedChannelResolvable | The channel to forward this message to. |
Returns: Promise<Message>Source
startThread
async
Create a new public thread from this message Parameters
| Name | Type | Description |
|---|---|---|
options? | StartThreadOptions | Options for starting a thread on this message |
Returns: Promise<ThreadChannel>Source
vote
Submits a poll vote for the current user. Returns a 204 empty response on success. Parameters
| Name | Type | Description |
|---|---|---|
ids | Array<number> | ID of the answer |
Returns: Promise<void>
// Vote multi choices
message.vote(1,2);
// Remove vote
message.vote();2
3
4
fetch
async
Fetch this message. Parameters
| Name | Type | Description |
|---|---|---|
force? | boolean | Whether to skip the cache check and request the API Default: true. |
Returns: Promise<Message>Source
fetchWebhook
async
Fetches the webhook used to create this message. Returns: Promise<?Webhook>Source
suppressEmbeds
Suppresses or unsuppresses embeds on a message. Parameters
| Name | Type | Description |
|---|---|---|
suppress? | boolean | If the embeds should be suppressed or not Default: true. |
Returns: Promise<Message>Source
removeAttachments
Removes the attachments from this message. Returns: Promise<Message>Source
resolveComponent
Resolves a component by a custom id. Parameters
| Name | Type | Description |
|---|---|---|
customId | string | The custom id to resolve against |
Returns: MessageActionRowComponentSource
equals
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? | APIMessage | Raw data passed through the WebSocket about this message |
Returns: booleanSource
inGuild
Whether this message is from a guild. Returns: booleanSource
toString
When concatenated with a string, this automatically concatenates the message's content instead of the object. Returns: string
// Logs: Message: This is a message!
console.log(`Message: ${message}`);2
clickButton
Click a specified button in the message based on the button's CustomID Parameters
| Name | Type | Description |
|---|---|---|
buttonid | string | customId of the button to click To be compatible with Components V2, the following methods have been removed in this version: - Clicking by coordinates (using ActionRow) - Clicking the first button in the message Currently, only clicking by CustomID is supported. |
Returns: Promise<(Message\|Modal)>Source
selectMenu
Select specific menu Parameters
| Name | Type | Description |
|---|---|---|
menu | number | string | Target |
values | Array<(UserResolvable|RoleResolvable|ChannelResolvable|string)> | Any value |
Returns: Promise<(Message\|Modal)>Source
markUnread
Marks the message as unread. Returns: Promise<void>Source
markRead
Marks the message as read. Returns: Promise<void>Source
report
Report Message Parameters
| Name | Type | Description |
|---|---|---|
breadcrumbs | Arrray<number> | Options for reporting |
elements? | Object | Metadata Default: {}. |
Returns: Promise<{report_id: Snowflake}>
// GET https://discord.com/api/v9/reporting/menu/message?variant=4
// Report Category
// - <hidden>MESSAGE_WELCOME (3)</hidden>
// - Something else (28)
// - Hacks, cheats, phishing or malicious links (72)
message.report([3, 28, 72]).then(console.log);
// { "report_id": "1199663489988440124" }2
3
4
5
6
7