Message

export class Message<InGuild extends boolean = boolean> extends Base
export class Message<InGuild extends boolean = boolean> extends Base
Represents a message on Discord.

Extends

Base
NameConstraintsOptionalDefaultDescription
InGuildbooleanYesbooleanNone
Group activity
applicationId:Snowflake | null
The id of the application of the interaction that sent this message, if any
A collection of attachments in the message - e.g. Pictures - mapped by their ids. This property requires the GatewayIntentBits.MessageContent privileged intent in a guild for messages that do not mention the client.
author:User
The author of the message
Readonly
bulkDeletable:boolean
Whether the message is bulk deletable by the client user
The call associated with the message
Readonly
The channel that the message was sent in
channelId:Snowflake
The id of the channel the message was sent in
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.
Readonly
client:Client<true>
The client that instantiated this
Inherited from Base
An array of action rows in the message. This property requires the GatewayIntentBits.MessageContent privileged intent in a guild for messages that do not mention the client.
content:string
The content of the message. This property requires the GatewayIntentBits.MessageContent privileged intent in a guild for messages that do not mention the client.
Readonly
createdAt:Date
The time the message was sent at
createdTimestamp:number
The timestamp the message was sent at
Readonly
crosspostable:boolean
Whether the message is crosspostable by the client user
Readonly
deletable:boolean
Whether the message is deletable by the client user
Readonly
editable:boolean
Whether the message is editable by the client user
Readonly
editedAt:Date | null
The time the message was last edited at (if applicable)
editedTimestamp:number | null
The timestamp the message was last edited at (if applicable)
embeds:Embed[]
An array of embeds in the message - e.g. YouTube Player. This property requires the GatewayIntentBits.MessageContent privileged intent in a guild for messages that do not mention the client.
Flags that are applied to the message
groupActivityApplication:ClientApplication | null
Supplemental application information for group activities
Readonly
guild:If<InGuild, Guild>
The guild the message was sent in (if in a guild channel)
guildId:If<InGuild, Snowflake>
The id of the guild the message was sent in, if any
Readonly
hasThread:boolean
Whether this message has a thread associated with it
The message's id
Deprecated
interaction:MessageInteraction | null
Use interactionMetadata instead.
Deprecated
Partial data of the interaction that this message is a reply to
interactionMetadata:MessageInteractionMetadata | null
Partial data of the interaction that this message is a result of
Readonly
member:GuildMember | null
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
mentions:MessageMentions<InGuild>
All valid mentions that the message contains
The message associated with the message reference
nonce:string | number | null
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
Readonly
partial:false
Whether or not this message is a partial
Readonly
pinnable:boolean
Whether the message is pinnable by the client user
pinned:boolean
Whether or not this message is pinned
poll:Poll | null
The poll that was sent with the message
position:number | null
A generally increasing integer (there may be gaps or duplicates) that represents the approximate position of the message in a thread.
reactions:ReactionManager
A manager of the reactions belonging to this message
Message reference data
roleSubscriptionData:RoleSubscriptionData | null
The data of the role subscription purchase or renewal. This is present on MessageType.RoleSubscriptionPurchase messages.
A collection of stickers in the message
system:boolean
Whether or not this message was sent by Discord, not actually a user (e.g. pin notifications)
Readonly
The thread started by this message This property is not suitable for checking whether a message has a thread, use hasThread instead.
Whether or not the message was Text-To-Speech
The type of the message
Readonly
url:string
The URL to jump to this message
webhookId:Snowflake | null
The id of the webhook that sent the message, if applicable
awaitMessageComponent(options?):Promise<MappedInteractionTypes<InGuild>[ComponentType]>
Collects a single component interaction that passes the filter. The Promise will reject if the time expires.
Example
// Collect a message component interaction
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
message.awaitMessageComponent({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was clicked!`))
.catch(console.error);
// Collect a message component interaction
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
message.awaitMessageComponent({ filter, time: 15_000 })
.then(interaction => console.log(`${interaction.customId} was clicked!`))
.catch(console.error);
NameConstraintsOptionalDefaultDescription
ComponentTypeMessageComponentTypeNoNone
NameTypeOptionalDescription
optionsAwaitMessageCollectorOptionsParams<ComponentType, InGuild>YesOptions to pass to the internal collector
awaitReactions(options?):Promise<Collection<Snowflake | string, MessageReaction>>
Similar to createReactionCollector but in promise form. Resolves with a collection of reactions that pass the specified filter.
Example
// 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);
// 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);
NameTypeOptionalDescription
optionsAwaitReactionsOptionsYesOptional options to pass to the internal collector
createMessageComponentCollector(options?):InteractionCollector<MappedInteractionTypes<InGuild>[ComponentType]>
Creates a message component interaction collector.
Example
// Create a message component interaction collector
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
collector.on('collect', i => console.log(`Collected ${i.customId}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
// Create a message component interaction collector
const filter = (interaction) => interaction.customId === 'button' && interaction.user.id === 'someId';
const collector = message.createMessageComponentCollector({ filter, time: 15_000 });
collector.on('collect', i => console.log(`Collected ${i.customId}`));
collector.on('end', collected => console.log(`Collected ${collected.size} items`));
NameConstraintsOptionalDefaultDescription
ComponentTypeMessageComponentTypeNoNone
NameTypeOptionalDescription
optionsMessageCollectorOptionsParams<ComponentType, InGuild>YesOptions to send to the collector
createReactionCollector(options?):ReactionCollector
Creates a reaction collector.
Example
// 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`));
// 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`));
NameTypeOptionalDescription
optionsReactionCollectorOptionsYesOptions to send to the collector
Publishes a message in an announcement channel to all channels following it.
Example
// Crosspost a message
if (message.channel.type === ChannelType.GuildAnnouncement) {
message.crosspost()
.then(() => console.log('Crossposted message'))
.catch(console.error);
}
// Crosspost a message
if (message.channel.type === ChannelType.GuildAnnouncement) {
message.crosspost()
.then(() => console.log('Crossposted message'))
.catch(console.error);
}
Deletes the message.
Example
// Delete a message
message.delete()
.then(msg => console.log(`Deleted message from ${msg.author.username}`))
.catch(console.error);
// Delete a message
message.delete()
.then(msg => console.log(`Deleted message from ${msg.author.username}`))
.catch(console.error);
edit(options):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Edits the content of the 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);
// 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);
NameTypeOptionalDescription
optionsstring | MessageEditOptions | MessagePayloadNoThe options to provide
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.
NameTypeOptionalDescription
messageMessageNoThe message to compare it to
rawDataunknownNoRaw data passed through the WebSocket about this message
fetch(force?):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Fetch this message.
NameTypeOptionalDescription
forcebooleanYesWhether to skip the cache check and request the API
fetchReference():Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Fetches the Message this crosspost/reply/pin-add references, if available to the client
fetchWebhook():Promise<Webhook>
Fetches the webhook used to create this message.
inGuild():this is Message<true>
Whether this message is from a guild.
pin(reason?):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Pins this message to the channel's pinned messages.
Example
// Pin a message
message.pin()
.then(console.log)
.catch(console.error)
// Pin a message
message.pin()
.then(console.log)
.catch(console.error)
NameTypeOptionalDescription
reasonstringYesReason for pinning
react(emoji):Promise<MessageReaction>
Adds a reaction to the message.
Example
// React to a message with a unicode emoji
message.react('🤔')
.then(console.log)
.catch(console.error);
// React to a message with a unicode emoji
message.react('🤔')
.then(console.log)
.catch(console.error);
Example
// React to a message with a custom emoji
message.react(message.guild.emojis.cache.get('123456789012345678'))
.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);
NameTypeOptionalDescription
emojiEmojiIdentifierResolvableNoThe emoji to react with
removeAttachments():Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Removes the attachments from this message.
reply(options):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Send an inline reply to this message.
Example
// Reply to a message
message.reply('This is a reply!')
.then(() => console.log(`Replied to message "${message.content}"`))
.catch(console.error);
// Reply to a message
message.reply('This is a reply!')
.then(() => console.log(`Replied to message "${message.content}"`))
.catch(console.error);
NameTypeOptionalDescription
optionsstring | MessagePayload | MessageReplyOptionsNoThe options to provide
resolveComponent(customId):MessageActionRowComponent | null
Resolves a component by a custom id.
Returns
NameTypeOptionalDescription
customIdstringNoThe custom id to resolve against
startThread(options):Promise<PublicThreadChannel<false>>
Create a new public thread from this message
NameTypeOptionalDescription
optionsStartThreadOptionsNoOptions for starting a thread on this message
suppressEmbeds(suppress?):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Suppresses or unsuppresses embeds on a message.
NameTypeOptionalDescription
suppressbooleanYesIf the embeds should be suppressed or not
toJSON():unknown
toString():string
When concatenated with a string, this automatically concatenates the message's content instead of the object.
Example
// Logs: Message: This is a message!
console.log(`Message: ${message}`);
// Logs: Message: This is a message!
console.log(`Message: ${message}`);
unpin(reason?):Promise<OmitPartialGroupDMChannel<Message<InGuild>>>
Unpins this message from the channel's pinned messages.
Example
// Unpin a message
message.unpin()
.then(console.log)
.catch(console.error)
// Unpin a message
message.unpin()
.then(console.log)
.catch(console.error)
NameTypeOptionalDescription
reasonstringYesReason for unpinning
valueOf():string