-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
sendFollowupMessage.ts
46 lines (44 loc) · 1.67 KB
/
sendFollowupMessage.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import type { Bot } from "../../../bot.ts";
import { InteractionResponse, Message } from "../../../mod.ts";
import { DiscordMessage } from "../../../types/discord.ts";
/**
* Sends a follow-up message to an interaction.
*
* @param bot - The bot instance to use to make the request.
* @param token - The interaction token to use, provided in the original interaction.
* @param options - The parameters for the creation of the message.
* @returns An instance of the created {@link Message}.
*
* @remarks
* ⚠️ Interaction tokens are only valid for _15 minutes_.
*
* By default, mentions are suppressed. To enable mentions, pass a mention object with the callback data.
*
* Unlike `sendMessage()`, this endpoint allows the bot user to act without:
* - Needing to be able to see the contents of the channel that the message is in. (`READ_MESSAGES` permission.)
* - Requiring the `MESSAGE_CONTENT` intent.
*
* Fires a _Message Create_ event.
*
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message}
*/
export async function sendFollowupMessage(
bot: Bot,
token: string,
options: InteractionResponse,
): Promise<Message> {
const result = await bot.rest.sendRequest<DiscordMessage>(bot.rest, {
url: bot.constants.routes.WEBHOOK(bot.applicationId, token),
method: "POST",
payload: bot.rest.createRequestBody(bot.rest, {
method: "POST",
body: {
...bot.transformers.reverse.interactionResponse(bot, options).data,
file: options.data?.file,
},
// remove authorization header
headers: { Authorization: "" },
}),
});
return bot.transformers.message(bot, result);
}