Skip to content

Message ​

classe · Source

Represents a message on Discord.

Extends: Base

Properties ​

channelId ​

channelId: Snowflake

The id of the channel the message was sent in Source

guildId ​

nullable

guildId: Snowflake

The id of the guild the message was sent in, if any Source

id ​

id: Snowflake

The message's id Source

position ​

nullable

position: number

A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread. Source

createdTimestamp ​

createdTimestamp: number

The timestamp the message was sent at Source

type ​

nullable

type: MessageType

The type of the message Source

system ​

nullable

system: boolean

Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications) Source

content ​

nullable

content: string

The content of the message Source

author ​

nullable

author: User

The author of the message Source

pinned ​

nullable

pinned: boolean

Whether or not this message is pinned Source

tts ​

nullable

tts: boolean

Whether or not the message was Text-To-Speech Source

nonce ​

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 Source

embeds ​

embeds: Array<MessageEmbed>

A list of embeds in the message - e.g. YouTube Player Source

components ​

components: Array<TopLevelComponent>

An array of components in the message Source

attachments ​

attachments: Collection<Snowflake, MessageAttachment>

A collection of attachments in the message - e.g. Pictures - mapped by their ids Source

stickers ​

stickers: Collection<Snowflake, Sticker>

A collection of stickers in the message Source

editedTimestamp ​

nullable

editedTimestamp: number

The timestamp the message was last edited at (if applicable) Source

reactions ​

reactions: ReactionManager

A manager of the reactions belonging to this message Source

mentions ​

mentions: MessageMentions

All valid mentions that the message contains Source

webhookId ​

nullable

webhookId: Snowflake

The id of the webhook that sent the message, if applicable Source

poll ​

nullable

poll: Poll

The poll that was sent with the message Source

groupActivityApplication ​

nullable

groupActivityApplication: Application

Supplemental application information for group activities Source

applicationId ​

nullable

applicationId: Snowflake

The id of the application of the interaction that sent this message, if any Source

activity ​

nullable

activity: MessageActivity

Group activity Source

flags ​

flags: Readonly<MessageFlags>

Flags that are applied to the message Source

reference ​

nullable

reference: MessageReference

Message reference data Source

interaction ​

nullable

interaction: MessageInteraction

Partial data of the interaction that this message is a reply to Source

messageSnapshots ​

messageSnapshots: Collection<Snowflake, Message>

The message snapshots associated with the message reference Source

call ​

nullable

call: MessageCall

The call associated with the message Source

deleted ​

deprecated

deleted: boolean

Whether or not the structure has been deleted Source

channel ​

readonly

channel: TextBasedChannels

The channel that the message was sent in Source

partial ​

readonly

partial: boolean

Whether or not this message is a partial Source

member ​

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 Source

createdAt ​

readonly

createdAt: Date

The time the message was sent at Source

editedAt ​

readonly · nullable

editedAt: Date

The time the message was last edited at (if applicable) Source

guild ​

readonly · nullable

guild: Guild

The guild the message was sent in (if in a guild channel) Source

hasThread ​

readonly

hasThread: boolean

Whether this message has a thread associated with it Source

thread ​

readonly · nullable

thread: ThreadChannel

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

url: string

The URL to jump to this message Source

cleanContent ​

readonly · nullable

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. Source

editable ​

readonly

editable: boolean

Whether the message is editable by the client user Source

deletable ​

readonly

deletable: boolean

Whether the message is deletable by the client user Source

bulkDeletable ​

readonly

bulkDeletable: boolean

Whether the message is bulk deletable by the client user Source

pinnable ​

readonly

pinnable: boolean

Whether the message is pinnable by the client user Source

crosspostable ​

readonly

crosspostable: boolean

Whether the message is crosspostable by the client user Source

isMessage ​

readonly

isMessage: boolean

Check data Source

client ​

readonly

client: Client

The client that instantiated this Source

Methods ​

createReactionCollector ​

createReactionCollector(options?: ReactionCollectorOptions): ReactionCollector

Creates a reaction collector. Parameters

NameTypeDescription
options?ReactionCollectorOptionsOptions to send to the collector Default: {}.

Returns: ReactionCollector

js
// 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`));

Source

awaitReactions ​

awaitReactions(options?: AwaitReactionsOptions): Promise<Collection<(string|Snowflake), MessageReaction>>

Similar to createReactionCollector but in promise form. Resolves with a collection of reactions that pass the specified filter. Parameters

NameTypeDescription
options?AwaitReactionsOptionsOptional options to pass to the internal collector Default: {}.

Returns: Promise<Collection<(string\|Snowflake), MessageReaction>>

js
// 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);

Source

fetchReference ​

async

async fetchReference(): Promise<Message>

Fetches the Message this crosspost/reply/pin-add references, if available to the client Returns: Promise<Message>Source

edit ​

async

async edit(options: string | MessagePayload | MessageEditOptions): Promise<Message>

Edits the content of the message. Parameters

NameTypeDescription
optionsstring | MessagePayload | MessageEditOptionsThe options to provide

Returns: Promise<Message>

js
// 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);

Source

crosspost ​

async

async crosspost(): Promise<Message>

Publishes a message in an announcement channel to all channels following it. Returns: Promise<Message>

js
// Crosspost a message
if (message.channel.type === 'GUILD_NEWS') {
  message.crosspost()
    .then(() => console.log('Crossposted message'))
    .catch(console.error);
}

Source

pin ​

async

async pin(reason?: string): Promise<Message>

Pins this message to the channel's pinned messages. Parameters

NameTypeDescription
reason?stringReason for pinning

Returns: Promise<Message>

js
// Pin a message
message.pin()
  .then(console.log)
  .catch(console.error)

Source

unpin ​

async

async unpin(reason?: string): Promise<Message>

Unpins this message from the channel's pinned messages. Parameters

NameTypeDescription
reason?stringReason for unpinning

Returns: Promise<Message>

js
// Unpin a message
message.unpin()
  .then(console.log)
  .catch(console.error)

Source

react ​

async

async react(emoji: EmojiIdentifierResolvable, burst?: boolean): Promise<MessageReaction>

Adds a reaction to the message. Parameters

NameTypeDescription
emojiEmojiIdentifierResolvableThe emoji to react with
burst?booleanSuper Reactions Default: false.

Returns: Promise<MessageReaction>

js
// React to a message with a unicode emoji
message.react('🤔')
  .then(console.log)
  .catch(console.error);
js
// React to a message with a custom emoji
message.react(message.guild.emojis.cache.get('123456789012345678'))
  .then(console.log)
  .catch(console.error);

Source

delete ​

async

async delete(): Promise<Message>

Deletes the message. Returns: Promise<Message>

js
// Delete a message
message.delete()
  .then(msg => console.log(`Deleted message from ${msg.author.username}`))
  .catch(console.error);

Source

reply ​

async

async reply(options: string | MessagePayload | ReplyMessageOptions): Promise<Message>

Send an inline reply to this message. Parameters

NameTypeDescription
optionsstring | MessagePayload | ReplyMessageOptionsThe options to provide

Returns: Promise<Message>

js
// Reply to a message
message.reply('This is a reply!')
  .then(() => console.log(`Replied to message "${message.content}"`))
  .catch(console.error);

Source

forward ​

forward(channel: TextBasedChannelResolvable): Promise<Message>

Forwards this message Parameters

NameTypeDescription
channelTextBasedChannelResolvableThe channel to forward this message to.

Returns: Promise<Message>Source

startThread ​

async

async startThread(options?: StartThreadOptions): Promise<ThreadChannel>

Create a new public thread from this message Parameters

NameTypeDescription
options?StartThreadOptionsOptions for starting a thread on this message

Returns: Promise<ThreadChannel>Source

vote ​

vote(ids: Array<number>): Promise<void>

Submits a poll vote for the current user. Returns a 204 empty response on success. Parameters

NameTypeDescription
idsArray<number>ID of the answer

Returns: Promise<void>

js
// Vote multi choices
message.vote(1,2);
// Remove vote
message.vote();

Source

fetch ​

async

async fetch(force?: boolean): Promise<Message>

Fetch this message. Parameters

NameTypeDescription
force?booleanWhether to skip the cache check and request the API Default: true.

Returns: Promise<Message>Source

fetchWebhook ​

async

async fetchWebhook(): Promise<?Webhook>

Fetches the webhook used to create this message. Returns: Promise<?Webhook>Source

suppressEmbeds ​

suppressEmbeds(suppress?: boolean): Promise<Message>

Suppresses or unsuppresses embeds on a message. Parameters

NameTypeDescription
suppress?booleanIf the embeds should be suppressed or not Default: true.

Returns: Promise<Message>Source

removeAttachments ​

removeAttachments(): Promise<Message>

Removes the attachments from this message. Returns: Promise<Message>Source

resolveComponent ​

resolveComponent(customId: string): MessageActionRowComponent

Resolves a component by a custom id. Parameters

NameTypeDescription
customIdstringThe custom id to resolve against

Returns: MessageActionRowComponentSource

equals ​

equals(message: Message, rawData?: APIMessage): 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

NameTypeDescription
messageMessageThe message to compare it to
rawData?APIMessageRaw data passed through the WebSocket about this message

Returns: booleanSource

inGuild ​

inGuild(): boolean

Whether this message is from a guild. Returns: booleanSource

toString ​

toString(): string

When concatenated with a string, this automatically concatenates the message's content instead of the object. Returns: string

js
// Logs: Message: This is a message!
console.log(`Message: ${message}`);

Source

clickButton ​

clickButton(buttonid: string): Promise<(Message|Modal)>

Click a specified button in the message based on the button's CustomID Parameters

NameTypeDescription
buttonidstringcustomId 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 ​

selectMenu(menu: number | string, values: Array<(UserResolvable|RoleResolvable|ChannelResolvable|string)>): Promise<(Message|Modal)>

Select specific menu Parameters

NameTypeDescription
menunumber | stringTarget
valuesArray<(UserResolvable|RoleResolvable|ChannelResolvable|string)>Any value

Returns: Promise<(Message\|Modal)>Source

markUnread ​

markUnread(): Promise<void>

Marks the message as unread. Returns: Promise<void>Source

markRead ​

markRead(): Promise<void>

Marks the message as read. Returns: Promise<void>Source

report ​

report(breadcrumbs: Arrray<number>, elements?: Object): Promise<{report_id: Snowflake}>

Report Message Parameters

NameTypeDescription
breadcrumbsArrray<number>Options for reporting
elements?ObjectMetadata Default: {}.

Returns: Promise<{report_id: Snowflake}>

js
// 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" }

Source

Unofficial software. Not affiliated with or supported by Discord.