Skip to content

MessageManager

classe · Source

Manages API methods for Messages and holds their cache.

Extends: CachedManager

Properties

channel

channel: TextBasedChannels

The channel that the messages belong to Source

cache

cache: Collection<Snowflake, Message>

The cache of Messages Source

_cache

readonly · private

_cache: Collection

The private cache of items for this manager. Source

holds

readonly · private

holds: function

The data structure belonging to this manager. Source

client

readonly

client: Client

The client that instantiated this Manager Source

Methods

fetch

fetch(message?: Snowflake | ChannelLogsQueryOptions, options?: BaseFetchOptions): Promise<(Message|Collection<Snowflake, Message>)>

Gets a message, or messages, from this channel. The returned Collection does not contain reaction users of the messages if they were not cached. Those need to be fetched separately in such a case. Parameters

NameTypeDescription
message?Snowflake | ChannelLogsQueryOptionsThe id of the message to fetch, or query parameters.
options?BaseFetchOptionsAdditional options for this fetch

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

js
// Get message
channel.messages.fetch('99539446449315840')
  .then(message => console.log(message.content))
  .catch(console.error);
js
// Get messages
channel.messages.fetch({ limit: 10 })
  .then(messages => console.log(`Received ${messages.size} messages`))
  .catch(console.error);
js
// Get messages and filter by user id
channel.messages.fetch()
  .then(messages => console.log(`${messages.filter(m => m.author.id === '84484653687267328').size} messages`))
  .catch(console.error);

Source

fetchPinned

async

async fetchPinned(cache?: boolean): Promise<Collection<Snowflake, Message>>

Fetches the pinned messages of this channel and returns a collection of them. The returned Collection does not contain any reaction data of the messages. Those need to be fetched separately. Parameters

NameTypeDescription
cache?booleanWhether to cache the message(s) Default: true.

Returns: Promise<Collection<Snowflake, Message>>

js
// Get pinned messages
channel.messages.fetchPinned()
  .then(messages => console.log(`Received ${messages.size} messages`))
  .catch(console.error);

Source

resolve

resolve(message: MessageResolvable): Message

Resolves a MessageResolvable to a Message object. Parameters

NameTypeDescription
messageMessageResolvableThe message resolvable to resolve

Returns: MessageSource

resolveId

resolveId(message: MessageResolvable): Snowflake

Resolves a MessageResolvable to a Message id. Parameters

NameTypeDescription
messageMessageResolvableThe message resolvable to resolve

Returns: SnowflakeSource

edit

async

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

Edits a message, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to edit
optionsstring | MessageEditOptions | MessagePayloadThe options to edit the message

Returns: Promise<Message>Source

crosspost

async

async crosspost(message: MessageResolvable): Promise<Message>

Publishes a message in an announcement channel to all channels following it, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to publish

Returns: Promise<Message>Source

pin

async

async pin(message: MessageResolvable, reason?: string): Promise<void>

Pins a message to the channel's pinned messages, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to pin
reason?stringReason for pinning

Returns: Promise<void>Source

unpin

async

async unpin(message: MessageResolvable, reason?: string): Promise<void>

Unpins a message from the channel's pinned messages, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to unpin
reason?stringReason for unpinning

Returns: Promise<void>Source

react

async

async react(message: MessageResolvable, emoji: EmojiIdentifierResolvable, burst?: boolean): Promise<void>

Adds a reaction to a message, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to react to
emojiEmojiIdentifierResolvableThe emoji to react with
burst?booleanSuper Reactions (Discord Nitro only) Default: false.

Returns: Promise<void>Source

delete

async

async delete(message: MessageResolvable): Promise<void>

Deletes a message, even if it's not cached. Parameters

NameTypeDescription
messageMessageResolvableThe message to delete

Returns: Promise<void>Source

async

async search(options: MessageSearchOptions): MessageSearchResult

Search Messages in the channel. Parameters

NameTypeDescription
optionsMessageSearchOptionsPerforms a search within the channel.

Returns: MessageSearchResultSource

endPoll

async

async endPoll(messageId: Snowflake): Promise<Message>

Ends a poll. Parameters

NameTypeDescription
messageIdSnowflakeThe id of the message

Returns: Promise<Message>Source

fetchPollAnswerVoters

async

async fetchPollAnswerVoters(options: FetchPollAnswerVotersOptions): Promise<Collection<Snowflake, User>>

Fetches the users that voted for a poll answer. Parameters

NameTypeDescription
optionsFetchPollAnswerVotersOptionsThe options for fetching the poll answer voters

Returns: Promise<Collection<Snowflake, User>>Source

Unofficial software. Not affiliated with or supported by Discord.