From 567db60475c8704661b2e788c9905ef364d6c00c Mon Sep 17 00:00:00 2001 From: Matthew1177 <56777713+Matthew1177@users.noreply.github.com> Date: Sun, 30 Jan 2022 03:56:38 -0800 Subject: [PATCH] feat(`Interaction`): add `.commandType` property to `CommandInteraction` and `AutocompleteInteraction` (#7357) --- .../discord.js/src/structures/AutocompleteInteraction.js | 6 ++++++ packages/discord.js/src/structures/CommandInteraction.js | 6 ++++++ .../src/structures/ContextMenuCommandInteraction.js | 7 ------- packages/discord.js/src/structures/Interaction.js | 8 ++++---- packages/discord.js/typings/index.d.ts | 3 ++- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/discord.js/src/structures/AutocompleteInteraction.js b/packages/discord.js/src/structures/AutocompleteInteraction.js index f9d32712fcfe..161bbe8580fd 100644 --- a/packages/discord.js/src/structures/AutocompleteInteraction.js +++ b/packages/discord.js/src/structures/AutocompleteInteraction.js @@ -30,6 +30,12 @@ class AutocompleteInteraction extends Interaction { */ this.commandName = data.data.name; + /** + * The invoked application command's type + * @type {ApplicationCommandType.ChatInput} + */ + this.commandType = data.data.type; + /** * Whether this interaction has already received a response * @type {boolean} diff --git a/packages/discord.js/src/structures/CommandInteraction.js b/packages/discord.js/src/structures/CommandInteraction.js index b7665cea0c40..abbbf0ee9423 100644 --- a/packages/discord.js/src/structures/CommandInteraction.js +++ b/packages/discord.js/src/structures/CommandInteraction.js @@ -33,6 +33,12 @@ class CommandInteraction extends Interaction { */ this.commandName = data.data.name; + /** + * The invoked application command's type + * @type {ApplicationCommandType} + */ + this.commandType = data.data.type; + /** * Whether the reply to this interaction has been deferred * @type {boolean} diff --git a/packages/discord.js/src/structures/ContextMenuCommandInteraction.js b/packages/discord.js/src/structures/ContextMenuCommandInteraction.js index 25fdaba74f56..360f97e322e0 100644 --- a/packages/discord.js/src/structures/ContextMenuCommandInteraction.js +++ b/packages/discord.js/src/structures/ContextMenuCommandInteraction.js @@ -26,13 +26,6 @@ class ContextMenuCommandInteraction extends CommandInteraction { * @type {Snowflake} */ this.targetId = data.data.target_id; - - /** - * The type of the target of the interaction; either {@link ApplicationCommandType.User} - * or {@link ApplicationCommandType.Message} - * @type {ApplicationCommandType.User|ApplicationCommandType.Message} - */ - this.targetType = data.data.type; } /** diff --git a/packages/discord.js/src/structures/Interaction.js b/packages/discord.js/src/structures/Interaction.js index 779d3ae3c483..a341708eaa31 100644 --- a/packages/discord.js/src/structures/Interaction.js +++ b/packages/discord.js/src/structures/Interaction.js @@ -164,7 +164,7 @@ class Interaction extends Base { * @returns {boolean} */ isChatInputCommand() { - return this.isCommand() && typeof this.targetId === 'undefined'; + return this.isCommand() && this.commandType === ApplicationCommandType.ChatInput; } /** @@ -172,7 +172,7 @@ class Interaction extends Base { * @returns {boolean} */ isContextMenuCommand() { - return this.isCommand() && typeof this.targetId !== 'undefined'; + return this.isCommand() && [ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType); } /** @@ -180,7 +180,7 @@ class Interaction extends Base { * @returns {boolean} */ isUserContextMenuCommand() { - return this.isContextMenuCommand() && this.targetType === ApplicationCommandType.User; + return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.User; } /** @@ -188,7 +188,7 @@ class Interaction extends Base { * @returns {boolean} */ isMessageContextMenuCommand() { - return this.isContextMenuCommand() && this.targetType === ApplicationCommandType.Message; + return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.Message; } /** diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index b3e3fb067249..56db640aa976 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -326,6 +326,7 @@ export abstract class CommandInteraction e public channelId: Snowflake; public commandId: Snowflake; public commandName: string; + public commandType: ApplicationCommandType; public deferred: boolean; public ephemeral: boolean | null; public replied: boolean; @@ -705,6 +706,7 @@ export class AutocompleteInteraction exten public channelId: Snowflake; public commandId: Snowflake; public commandName: string; + public commandType: ApplicationCommandType.ChatInput; public responded: boolean; public options: Omit, 'getMessage'>; public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>; @@ -785,7 +787,6 @@ export class ContextMenuCommandInteraction | 'getSubcommand' >; public targetId: Snowflake; - public targetType: Exclude; public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>; public inCachedGuild(): this is ContextMenuCommandInteraction<'cached'>; public inRawGuild(): this is ContextMenuCommandInteraction<'raw'>;