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

This commit is contained in:
Awesome Stickz
2026-01-18 13:37:49 +05:30
committed by GitHub
parent 27c261fee2
commit 8a2eb9594d
2 changed files with 13 additions and 8 deletions

View File

@@ -42,9 +42,18 @@ export const baseInteraction: SetupDesiredProps<Interaction, CompleteDesiredProp
// If user provides a string, change it to a response object
if (typeof response === 'string') response = { content: response };
// If user provides an object, determine if it should be an autocomplete or a modal response
if (response.title) type = InteractionResponseTypes.Modal;
if (this.type === InteractionTypes.ApplicationCommandAutocomplete) type = InteractionResponseTypes.ApplicationCommandAutocompleteResult;
// If user provides a type, use it
if (options?.type) type = options.type;
// 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) {
response.flags ??= 0;
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.
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(
this.id,
this.token,

View File

@@ -994,7 +994,7 @@ export interface Interaction {
*/
respond: (
response: string | InteractionCallbackData,
options?: { isPrivate?: boolean; withResponse?: boolean },
options?: { isPrivate?: boolean; withResponse?: boolean; type?: InteractionResponseTypes },
) => Promise<Message | InteractionCallbackResponse | void>;
/**
* Edit the original response of an interaction or a followup if the message id is provided.