Skip to main content
Version: 0.9.0

Class: Message

The base class for all structures.

Extends​

Constructors​

Constructor​

new Message(client, data): Message

Parameters​

ParameterType
clientClient
data{ }

Returns​

Message

Overrides​

Base.constructor

Properties​

attachments​

attachments: Attachment[] = []


authorId​

authorId: string


cachedAt​

cachedAt: number

Inherited from​

Base.cachedAt


channelId​

channelId: string


client​

protected readonly client: Client

Inherited from​

Base.client


content​

content: string | null = null


createdAt​

createdAt: Date


createdTimestamp​

createdTimestamp: number


editedAt​

editedAt: Date | null = null


embeds​

embeds: ({ } | { } | { } | { } | { })[] | null = []


flags​

flags: number = 0


id​

readonly id: string

Inherited from​

Base.id


interactions​

interactions: Interaction | null = null


masquerade​

masquerade: Masquerade | null = null


mentions​

mentions: MessageMentions


pinned​

pinned: boolean | null = false


reactions​

reactions: Record<string, string[]> = {}


replies​

replies: string[] | null = []

Accessors​

author​

Get Signature​

get author(): User | undefined

Gets the Global User object from cache

Returns​

User | undefined


channel​

Get Signature​

get channel(): BaseChannel | undefined

Gets the Channel object from cache

Returns​

BaseChannel | undefined


member​

Get Signature​

get member(): Member | undefined

Gets the Server Member object (if sent in a server)

Returns​

Member | undefined


server​

Get Signature​

get server(): Server | undefined

Gets the Server object from cache

Returns​

Server | undefined


serverId​

Get Signature​

get serverId(): string | undefined

Gets the Server ID if this message was sent in a server channel

Returns​

string | undefined

Methods​

_clone()​

_clone(): this

Helper to quickly clone a structure

Returns​

this

Inherited from​

Base._clone


_patch()​

_patch(data): void

Parameters​

ParameterType
data{ }

Returns​

void


[custom]()​

[custom](depth, options, inspect): string

Parameters​

ParameterType
depthnumber
optionsInspectOptions
inspecttypeof inspect

Returns​

string


awaitReactions()​

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

Awaits reactions on this message.

Parameters​

ParameterTypeDescription
options?ReactionCollectorOptionsThe options for the collector.

Returns​

Promise<Collection<string, MessageReaction>>

A promise that resolves to a collection of reactions collected.

Example​

// Await reactions
const filter = (reaction) => reaction.emoji.id === '123' && reaction.users.has(author.id);
message.awaitReactions({ filter, max: 1, time: 60000 })
.then(collected => console.log(collected.size))
.catch(console.error);

clearReactions()​

clearReactions(): Promise<void>

Remove all reactions from this message

Returns​

Promise<void>

Throws​

If the API request fails.

Example​

await message.clearReactions();

createReactionCollector()​

createReactionCollector(options?): ReactionCollector

Creates a ReactionCollector to collect reactions on this message.

Parameters​

ParameterTypeDescription
options?ReactionCollectorOptionsThe options for the collector.

Returns​

ReactionCollector

A new ReactionCollector instance.

Example​

const collector = message.createReactionCollector({ time: 15000 });
collector.on('collect', (reaction) => console.log(`Collected ${reaction.emojiId} from ${reaction.userId}`));
collector.on('end', (collected) => console.log(`Collected ${collected.size} items`));

delete()​

delete(): Promise<void>

Deletes this message.

Returns​

Promise<void>


edit()​

edit(contentOrOptions): Promise<Message>

Edits this message.

Parameters​

ParameterTypeDescription
contentOrOptionsstring | MessageOptionsThe new content or options for the message.

Returns​

Promise<Message>


equals()​

equals(other): boolean

Compares this object with another to see if they represent the same entity.

Parameters​

ParameterType
otherstring | Base

Returns​

boolean

Inherited from​

Base.equals


pin()​

pin(): Promise<void>

Pins this message.

Returns​

Promise<void>


react()​

react(reaction): Promise<void>

React to this message

Parameters​

ParameterTypeDescription
reactionstringThe emoji to react with. Can be a Unicode emoji or a custom emoji ID.

Returns​

Promise<void>

Throws​

If the API request fails.

Example​

await message.react("👍");
await message.react("customEmojiId");

removeReaction()​

removeReaction(reaction, userId?, removeAll?): Promise<void>

Remove a reaction from this message

Parameters​

ParameterTypeDescription
reactionstringThe emoji to remove. Can be a Unicode emoji or a custom emoji ID.
userId?UserResolvableThe ID of the user whose reaction to remove. If not provided, removes the current user's reaction.
removeAll?booleanRemove all reactions of this type.

Returns​

Promise<void>

Throws​

If both userId and removeAll are provided, or if the API request fails.

Example​

// Remove the current user's reaction
await message.removeReaction("👍");
// Remove a specific user's reaction
await message.removeReaction("👍", userId);
// Remove all reactions of this type
await message.removeReaction("👍", undefined, true);

reply()​

reply(contentOrOptions): Promise<Message>

Parameters​

ParameterType
contentOrOptionsstring | MessageOptions

Returns​

Promise<Message>


toString()​

toString(): string

Returns the UUID string when the object is cast to a string.

Returns​

string

Inherited from​

Base.toString


unpin()​

unpin(): Promise<void>

Unpins this message.

Returns​

Promise<void>