diff --git a/.changeset/lazy-phones-complain.md b/.changeset/lazy-phones-complain.md new file mode 100644 index 00000000..35335494 --- /dev/null +++ b/.changeset/lazy-phones-complain.md @@ -0,0 +1,5 @@ +--- +"@buape/carbon": patch +--- + +feat: add followup messages for interactions diff --git a/packages/carbon/src/abstracts/BaseComponentInteraction.ts b/packages/carbon/src/abstracts/BaseComponentInteraction.ts index ac570c07..d87d6c1f 100644 --- a/packages/carbon/src/abstracts/BaseComponentInteraction.ts +++ b/packages/carbon/src/abstracts/BaseComponentInteraction.ts @@ -2,6 +2,7 @@ import { type APIMessageComponentInteraction, type ComponentType, InteractionResponseType, + type RESTPostAPIInteractionCallbackJSONBody, Routes } from "discord-api-types/v10" import type { Client } from "../classes/Client.js" @@ -29,7 +30,7 @@ export class BaseComponentInteraction extends BaseInteraction extends Base { { body: { ...data, + embeds: data.embeds?.map((embed) => embed.serialize()), components: data.components?.map((row) => row.serialize()) - }, + } as RESTPatchAPIInteractionOriginalResponseJSONBody, files: options.files } ) @@ -173,10 +177,11 @@ export abstract class BaseInteraction extends Base { type: InteractionResponseType.ChannelMessageWithSource, data: { ...data, + embeds: data.embeds?.map((embed) => embed.serialize()), components: data.components?.map((row) => row.serialize()), - ephemeral: options.ephemeral ?? this.defaultEphemeral + flags: options.ephemeral ? 64 : undefined } - }, + } as RESTPostAPIInteractionCallbackJSONBody, files: options.files } ) @@ -196,8 +201,8 @@ export abstract class BaseInteraction extends Base { { body: { type: InteractionResponseType.DeferredChannelMessageWithSource, - ephemeral: this.defaultEphemeral - } + flags: this.defaultEphemeral ? 64 : undefined + } as RESTPostAPIInteractionCallbackJSONBody } ) } @@ -216,7 +221,27 @@ export abstract class BaseInteraction extends Base { body: { type: InteractionResponseType.Modal, data: modal.serialize() - } + } as RESTPostAPIInteractionCallbackJSONBody + } + ) + } + + /** + * Send a followup message to the interaction + */ + async followUp( + reply: InteractionReplyData, + options: InteractionReplyOptions = {} + ) { + await this.client.rest.post( + Routes.webhook(this.client.options.clientId, this.rawData.token), + { + body: { + ...reply, + embeds: reply.embeds?.map((embed) => embed.serialize()), + components: reply.components?.map((row) => row.serialize()), + flags: options.ephemeral ? 64 : undefined + } as RESTPostAPIInteractionFollowupJSONBody } ) } diff --git a/packages/carbon/src/internals/ModalInteraction.ts b/packages/carbon/src/internals/ModalInteraction.ts index 0e88219e..36b2bbb3 100644 --- a/packages/carbon/src/internals/ModalInteraction.ts +++ b/packages/carbon/src/internals/ModalInteraction.ts @@ -1,6 +1,7 @@ import { InteractionResponseType, Routes, + type RESTPostAPIInteractionCallbackJSONBody, type APIModalSubmitInteraction } from "discord-api-types/v10" import { BaseInteraction } from "../abstracts/BaseInteraction.js" @@ -28,7 +29,7 @@ export class ModalInteraction extends BaseInteraction { body: { type: InteractionResponseType.DeferredMessageUpdate - } + } as RESTPostAPIInteractionCallbackJSONBody } ) }