Skip to content

Commit

Permalink
feat: restore missing typeguards (#8328)
Browse files Browse the repository at this point in the history
  • Loading branch information
monbrey committed Jul 25, 2022
1 parent 4fc2c60 commit 77ed407
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
32 changes: 32 additions & 0 deletions packages/discord.js/src/structures/BaseInteraction.js
Expand Up @@ -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}
Expand All @@ -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}
Expand Down
4 changes: 4 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -1527,9 +1527,13 @@ export class BaseInteraction<Cached extends CacheType = CacheType> extends Base
public inCachedGuild(): this is BaseInteraction<'cached'>;
public inRawGuild(): this is BaseInteraction<'raw'>;
public isButton(): this is ButtonInteraction<Cached>;
public isAutocomplete(): this is AutocompleteInteraction<Cached>;
public isChatInputCommand(): this is ChatInputCommandInteraction<Cached>;
public isCommand(): this is CommandInteraction<Cached>;
public isContextMenuCommand(): this is ContextMenuCommandInteraction<Cached>;
public isMessageComponent(): this is MessageComponentInteraction<Cached>;
public isMessageContextMenuCommand(): this is MessageContextMenuCommandInteraction<Cached>;
public isModalSubmit(): this is ModalSubmitInteraction<Cached>;
public isUserContextMenuCommand(): this is UserContextMenuCommandInteraction<Cached>;
public isSelectMenu(): this is SelectMenuInteraction<Cached>;
public isRepliable(): this is this & InteractionResponseFields<Cached>;
Expand Down

0 comments on commit 77ed407

Please sign in to comment.