feat(bot): add options.type to interaction.respond() (#4692)

This commit is contained in:
Awesome Stickz
2026-01-18 09:07:49 +01:00
committed by GitHub
parent 27c261fee2
commit 8a2eb9594d
2 changed files with 13 additions and 8 deletions
+12 -7
View File
@@ -42,9 +42,18 @@ export const baseInteraction: SetupDesiredProps<Interaction, CompleteDesiredProp
// If user provides a string, change it to a response object // If user provides a string, change it to a response object
if (typeof response === 'string') response = { content: response }; if (typeof response === 'string') response = { content: response };
// If user provides an object, determine if it should be an autocomplete or a modal response // If user provides a type, use it
if (response.title) type = InteractionResponseTypes.Modal; if (options?.type) type = options.type;
if (this.type === InteractionTypes.ApplicationCommandAutocomplete) type = InteractionResponseTypes.ApplicationCommandAutocompleteResult; // Otherwise, determine if it should be an autocomplete or a modal response
else {
if (response.title) type = InteractionResponseTypes.Modal;
if (this.type === InteractionTypes.ApplicationCommandAutocomplete) type = InteractionResponseTypes.ApplicationCommandAutocompleteResult;
}
// Modals cannot be chained
if (this.type === InteractionTypes.ModalSubmit && type === InteractionResponseTypes.Modal)
throw new Error('Cannot respond to a modal interaction with another modal.');
if (type === InteractionResponseTypes.ChannelMessageWithSource && options?.isPrivate) { if (type === InteractionResponseTypes.ChannelMessageWithSource && options?.isPrivate) {
response.flags ??= 0; response.flags ??= 0;
response.flags |= MessageFlags.Ephemeral; response.flags |= MessageFlags.Ephemeral;
@@ -53,10 +62,6 @@ export const baseInteraction: SetupDesiredProps<Interaction, CompleteDesiredProp
// Since this has already been given a response, any further responses must be followups. // Since this has already been given a response, any further responses must be followups.
if (this.acknowledged) return await this.bot.helpers.sendFollowupMessage(this.token, response); if (this.acknowledged) return await this.bot.helpers.sendFollowupMessage(this.token, response);
// Modals cannot be chained
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( const result = await this.bot.helpers.sendInteractionResponse(
this.id, this.id,
this.token, this.token,
+1 -1
View File
@@ -994,7 +994,7 @@ export interface Interaction {
*/ */
respond: ( respond: (
response: string | InteractionCallbackData, response: string | InteractionCallbackData,
options?: { isPrivate?: boolean; withResponse?: boolean }, options?: { isPrivate?: boolean; withResponse?: boolean; type?: InteractionResponseTypes },
) => Promise<Message | InteractionCallbackResponse | void>; ) => Promise<Message | InteractionCallbackResponse | void>;
/** /**
* Edit the original response of an interaction or a followup if the message id is provided. * Edit the original response of an interaction or a followup if the message id is provided.