From 805051274bf55d76e48be52a8d59f576a326a064 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 25 Feb 2022 13:56:34 +0000 Subject: [PATCH 1/3] feat: backport #7259 --- src/structures/Interaction.js | 10 ++++++++++ typings/index.d.ts | 12 ++++++++++++ typings/index.test-d.ts | 11 +++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/structures/Interaction.js b/src/structures/Interaction.js index e1a5d410fa7e..4676a3484097 100644 --- a/src/structures/Interaction.js +++ b/src/structures/Interaction.js @@ -226,6 +226,16 @@ class Interaction extends Base { MessageComponentTypes[this.componentType] === MessageComponentTypes.SELECT_MENU ); } + + /** + * Indicates whether this interaction can be replied to. + * @returns {boolean} + */ + isRepliable() { + return ![InteractionTypes.PING, InteractionTypes.APPLICATION_COMMAND_AUTOCOMPLETE].includes( + InteractionTypes[this.type], + ); + } } module.exports = Interaction; diff --git a/typings/index.d.ts b/typings/index.d.ts index 9a8f4fa413e3..28b8027e6a44 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -320,6 +320,17 @@ export type GuildCacheMessage = CacheTypeReducer< Message | APIMessage >; +export interface InteractionResponseFields { + reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; + reply(options: string | MessagePayload | InteractionReplyOptions): Promise; + deleteReply(): Promise; + editReply(options: string | MessagePayload | WebhookEditMessageOptions): Promise>; + deferReply(options: InteractionDeferReplyOptions & { fetchReply: true }): Promise>; + deferReply(options?: InteractionDeferReplyOptions): Promise; + fetchReply(): Promise>; + followUp(options: string | MessagePayload | InteractionReplyOptions): Promise>; +} + export abstract class BaseCommandInteraction extends Interaction { public readonly command: ApplicationCommand | ApplicationCommand<{ guild: GuildResolvable }> | null; public options: Omit< @@ -1350,6 +1361,7 @@ export class Interaction extends Base { public isMessageContextMenu(): this is MessageContextMenuInteraction; public isMessageComponent(): this is MessageComponentInteraction; public isSelectMenu(): this is SelectMenuInteraction; + public isRepliable(): this is this & InteractionResponseFields; } export class InteractionCollector extends Collector { diff --git a/typings/index.test-d.ts b/typings/index.test-d.ts index 9d9281bc1422..0a78e3093440 100644 --- a/typings/index.test-d.ts +++ b/typings/index.test-d.ts @@ -93,6 +93,7 @@ import { MessageActionRowComponent, MessageSelectMenu, PartialDMChannel, + InteractionResponseFields, } from '.'; import type { ApplicationCommandOptionTypes } from './enums'; import { expectAssignable, expectDeprecated, expectNotAssignable, expectNotType, expectType } from 'tsd'; @@ -1145,6 +1146,16 @@ client.on('interactionCreate', async interaction => { expectType(interaction.options.getSubcommandGroup(booleanValue)); expectType(interaction.options.getSubcommandGroup(false)); } + + if (interaction.isRepliable()) { + expectAssignable(interaction); + interaction.reply('test'); + } + + if (interaction.isCommand() && interaction.isRepliable()) { + expectAssignable(interaction); + expectAssignable(interaction); + } }); declare const shard: Shard; From 7c1d17c45c413a64866c412f8d3d840cd5ae6834 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 25 Feb 2022 21:25:10 +0000 Subject: [PATCH 2/3] types: Add properties --- typings/index.d.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index 28b8027e6a44..d615047ddbd5 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -321,6 +321,9 @@ export type GuildCacheMessage = CacheTypeReducer< >; export interface InteractionResponseFields { + deferred: boolean; + ephemeral: boolean | null; + replied: boolean; reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; reply(options: string | MessagePayload | InteractionReplyOptions): Promise; deleteReply(): Promise; From fd5b2967ec7b7413e8be8614f017c0fce7244dfb Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Sat, 5 Mar 2022 20:13:53 +0000 Subject: [PATCH 3/3] types(InteractionResponseFields): add webhook --- typings/index.d.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/typings/index.d.ts b/typings/index.d.ts index d615047ddbd5..f9dd36945374 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -324,6 +324,7 @@ export interface InteractionResponseFields deferred: boolean; ephemeral: boolean | null; replied: boolean; + webhook: InteractionWebhook; reply(options: InteractionReplyOptions & { fetchReply: true }): Promise>; reply(options: string | MessagePayload | InteractionReplyOptions): Promise; deleteReply(): Promise;