Class: MessageManager
Extends
BaseManager<string,Message,RawMessage>
Constructors
Constructor
new MessageManager(
client,channel,limit?):MessageManager
Parameters
| Parameter | Type | Default value |
|---|---|---|
client | Client | undefined |
channel | BaseChannel | undefined |
limit | number | Infinity |
Returns
MessageManager
Overrides
BaseManager<string, Message, RawMessage>.constructor
Properties
cache
cache:
Collection<string,Message>
Inherited from
BaseManager.cache
channel
channel:
BaseChannel
client
client:
Client
Inherited from
BaseManager.client
Methods
[custom]()
[custom]():
Collection<string,Message>
Returns
Collection<string, Message>
clearReactions()
clearReactions(
message):Promise<void>
Remove all reactions from a message Requires ManageMessages permission.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to clear reactions from. |
Returns
Promise<void>
Throws
If the API request fails.
Example
await channel.messages.clearReactions(messageId);
construct()
protectedconstruct(data):Message
Tell BaseManager how to build a Message
Parameters
| Parameter | Type |
|---|---|
data | { } |
Returns
Overrides
BaseManager.construct
delete()
delete(
message):Promise<void>
Deletes a message from the channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to delete. |
Returns
Promise<void>
edit()
edit(
message,contentOrOptions):Promise<Message>
Edits an existing message.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable (object or ID) to edit. |
contentOrOptions | string | MessageOptions | The new content or options. |
Returns
Promise<Message>
A promise that resolves to the updated Message.
extractId()
protectedextractId(data):string
Tell BaseManager how to find the ID for Messages
Parameters
| Parameter | Type |
|---|---|
data | { } |
Returns
string
Overrides
BaseManager.extractId
fetch()
fetch(
id):Promise<Message>
Parameters
| Parameter | Type |
|---|---|
id | string |
Returns
Promise<Message>
fetchMany()
fetchMany(
options?):Promise<Collection<string,Message>>
Fetches multiple messages from the channel using specific filter parameters.
Parameters
| Parameter | Type | Description |
|---|---|---|
options | MessageFetchOptions | The query parameters to filter the fetched messages. |
Returns
Promise<Collection<string, Message>>
A promise that resolves to a Collection of fetched Messages.
Throws
If the API request fails.
Example
// Fetch the last 50 messages in the channel
const messages = await channel.messages.fetchMany({ limit: 50, sort: "Latest" });
// Fetch 20 messages before a specific message ID
const history = await channel.messages.fetchMany({ limit: 20, before: "01H..." });
pin()
pin(
message):Promise<void>
Pins a message in the channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to pin. |
Returns
Promise<void>
react()
react(
message,reaction):Promise<void>
React to a message
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to react to. |
reaction | string | The 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 channel.messages.react(messageId, "👍");
await channel.messages.react(messageId, "customEmojiId");
removeReaction()
removeReaction(
message,reaction,userId?,removeAll?):Promise<void>
Remove a reaction(s) from a message Requires ManageMessages if changing others' reactions.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to remove the reaction from. |
reaction | string | The emoji to remove. Can be a unicode emoji or a custom emoji ID. |
userId? | UserResolvable | The ID of the user whose reaction to remove. If not provided, removes the current user's reaction. |
removeAll? | boolean | Remove 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 channel.messages.removeReaction(messageId, "👍");
// Remove a specific user's reaction
await channel.messages.removeReaction(messageId, "👍", userId);
// Remove all reactions of this type
await channel.messages.removeReaction(messageId, "👍", undefined, true);
resolveId()
resolveId(
message):string
Parameters
| Parameter | Type |
|---|---|
message | MessageResolvable |
Returns
string
send()
send(
contentOrOptions):Promise<Message>
Sends a new message to this channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
contentOrOptions | string | MessageOptions | The string content or message options payload. |
Returns
Promise<Message>
A promise that resolves to the sent Message.
unpin()
unpin(
message):Promise<void>
Unpins a message in the channel.
Parameters
| Parameter | Type | Description |
|---|---|---|
message | MessageResolvable | The MessageResolvable to unpin. |
Returns
Promise<void>