From 77ed407f6aadb68e729470c5269e9b526cb1b3f0 Mon Sep 17 00:00:00 2001 From: Ryan Munro Date: Mon, 25 Jul 2022 19:12:48 +1000 Subject: [PATCH] feat: restore missing typeguards (#8328) --- .../src/structures/BaseInteraction.js | 32 +++++++++++++++++++ packages/discord.js/typings/index.d.ts | 4 +++ 2 files changed, 36 insertions(+) diff --git a/packages/discord.js/src/structures/BaseInteraction.js b/packages/discord.js/src/structures/BaseInteraction.js index 1f8b00bcaee3..6177fb29ed12 100644 --- a/packages/discord.js/src/structures/BaseInteraction.js +++ b/packages/discord.js/src/structures/BaseInteraction.js @@ -193,6 +193,22 @@ class BaseInteraction extends Base { return Boolean(this.guildId && !this.guild && this.member); } + /** + * Indicates whether this interaction is an {@link AutocompleteInteraction} + * @returns {boolean} + */ + isAutocomplete() { + return this.type === InteractionType.ApplicationCommandAutocomplete; + } + + /** + * Indicates whether this interaction is a {@link CommandInteraction} + * @returns {boolean} + */ + isCommand() { + return this.type === InteractionType.ApplicationCommand; + } + /** * Indicates whether this interaction is a {@link ChatInputCommandInteraction}. * @returns {boolean} @@ -212,6 +228,22 @@ class BaseInteraction extends Base { ); } + /** + * Indicates whether this interaction is a {@link MessageComponentInteraction} + * @returns {boolean} + */ + isMessageComponent() { + return this.type === InteractionType.MessageComponent; + } + + /** + * Indicates whether this interaction is a {@link ModalSubmitInteraction} + * @returns {boolean} + */ + isModalSubmit() { + return this.type === InteractionType.ModalSubmit; + } + /** * Indicates whether this interaction is a {@link UserContextMenuCommandInteraction} * @returns {boolean} diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index 43d85cd44980..a4ef21181b82 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1527,9 +1527,13 @@ export class BaseInteraction extends Base public inCachedGuild(): this is BaseInteraction<'cached'>; public inRawGuild(): this is BaseInteraction<'raw'>; public isButton(): this is ButtonInteraction; + public isAutocomplete(): this is AutocompleteInteraction; public isChatInputCommand(): this is ChatInputCommandInteraction; + public isCommand(): this is CommandInteraction; public isContextMenuCommand(): this is ContextMenuCommandInteraction; + public isMessageComponent(): this is MessageComponentInteraction; public isMessageContextMenuCommand(): this is MessageContextMenuCommandInteraction; + public isModalSubmit(): this is ModalSubmitInteraction; public isUserContextMenuCommand(): this is UserContextMenuCommandInteraction; public isSelectMenu(): this is SelectMenuInteraction; public isRepliable(): this is this & InteractionResponseFields;