From 8fd277924f80119222dd0a2e3c6f52682c80059b Mon Sep 17 00:00:00 2001 From: Fleny Date: Mon, 4 Aug 2025 08:46:47 +0200 Subject: [PATCH] fix(bot): ACK the interaction only after a successful response (#4280) --- packages/bot/src/transformers/interaction.ts | 26 +++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/packages/bot/src/transformers/interaction.ts b/packages/bot/src/transformers/interaction.ts index 32bec5bc0..d32aea4d1 100644 --- a/packages/bot/src/transformers/interaction.ts +++ b/packages/bot/src/transformers/interaction.ts @@ -51,8 +51,14 @@ export const baseInteraction: InternalBot['transformers']['$inferredTypes']['int if (this.type === InteractionTypes.ModalSubmit && type === InteractionResponseTypes.Modal) throw new Error('Cannot respond to a modal interaction with another modal.') + const result = await this.bot.helpers.sendInteractionResponse( + this.id, + this.token, + { type, data: response }, + { withResponse: options?.withResponse }, + ) this.acknowledged = true - return await this.bot.helpers.sendInteractionResponse(this.id, this.token, { type, data: response }, { withResponse: options?.withResponse }) + return result }, async edit(response, messageId, options) { if (this.type === InteractionTypes.ApplicationCommandAutocomplete) throw new Error('Cannot edit an autocomplete interaction.') @@ -68,13 +74,14 @@ export const baseInteraction: InternalBot['transformers']['$inferredTypes']['int if (this.type !== InteractionTypes.MessageComponent && this.type !== InteractionTypes.ModalSubmit) throw new Error("This interaction has not been responded to yet and this isn't a MessageComponent or ModalSubmit interaction.") - this.acknowledged = true - return await this.bot.helpers.sendInteractionResponse( + const result = await this.bot.helpers.sendInteractionResponse( this.id, this.token, { type: InteractionResponseTypes.UpdateMessage, data: response }, options, ) + this.acknowledged = true + return result } return await this.bot.helpers.editOriginalInteractionResponse(this.token, response) @@ -86,14 +93,19 @@ export const baseInteraction: InternalBot['transformers']['$inferredTypes']['int if (this.type !== InteractionTypes.MessageComponent && this.type !== InteractionTypes.ModalSubmit) throw new Error("Cannot defer to then edit an interaction that isn't a MessageComponent or ModalSubmit interaction.") + const result = await this.bot.helpers.sendInteractionResponse( + this.id, + this.token, + { type: InteractionResponseTypes.DeferredUpdateMessage }, + options, + ) this.acknowledged = true - return await this.bot.helpers.sendInteractionResponse(this.id, this.token, { type: InteractionResponseTypes.DeferredUpdateMessage }, options) + return result }, async defer(isPrivate, options) { if (this.acknowledged) throw new Error('Cannot defer an already responded interaction.') - this.acknowledged = true - return await this.bot.helpers.sendInteractionResponse( + const result = await this.bot.helpers.sendInteractionResponse( this.id, this.token, { @@ -104,6 +116,8 @@ export const baseInteraction: InternalBot['transformers']['$inferredTypes']['int }, options, ) + this.acknowledged = true + return result }, async delete(messageId) { if (this.type === InteractionTypes.ApplicationCommandAutocomplete) throw new Error('Cannot delete an autocomplete interaction')