mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 01:10:07 +00:00
feat(bot): add options.type to interaction.respond() (#4692)
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user