Skip to content

Commit

Permalink
feat(Interaction): add .commandType property to `CommandInteracti…
Browse files Browse the repository at this point in the history
…on` and `AutocompleteInteraction` (#7357)
  • Loading branch information
Matthew1177 committed Jan 30, 2022
1 parent fbb1d03 commit 567db60
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 12 deletions.
6 changes: 6 additions & 0 deletions packages/discord.js/src/structures/AutocompleteInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
6 changes: 6 additions & 0 deletions packages/discord.js/src/structures/CommandInteraction.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions packages/discord.js/src/structures/Interaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,31 +164,31 @@ class Interaction extends Base {
* @returns {boolean}
*/
isChatInputCommand() {
return this.isCommand() && typeof this.targetId === 'undefined';
return this.isCommand() && this.commandType === ApplicationCommandType.ChatInput;
}

/**
* Indicates whether this interaction is a {@link ContextMenuCommandInteraction}
* @returns {boolean}
*/
isContextMenuCommand() {
return this.isCommand() && typeof this.targetId !== 'undefined';
return this.isCommand() && [ApplicationCommandType.User, ApplicationCommandType.Message].includes(this.commandType);
}

/**
* Indicates whether this interaction is a {@link UserContextMenuCommandInteraction}
* @returns {boolean}
*/
isUserContextMenuCommand() {
return this.isContextMenuCommand() && this.targetType === ApplicationCommandType.User;
return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.User;
}

/**
* Indicates whether this interaction is a {@link MessageContextMenuCommandInteraction}
* @returns {boolean}
*/
isMessageContextMenuCommand() {
return this.isContextMenuCommand() && this.targetType === ApplicationCommandType.Message;
return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.Message;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion packages/discord.js/typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
public channelId: Snowflake;
public commandId: Snowflake;
public commandName: string;
public commandType: ApplicationCommandType;
public deferred: boolean;
public ephemeral: boolean | null;
public replied: boolean;
Expand Down Expand Up @@ -705,6 +706,7 @@ export class AutocompleteInteraction<Cached extends CacheType = CacheType> exten
public channelId: Snowflake;
public commandId: Snowflake;
public commandName: string;
public commandType: ApplicationCommandType.ChatInput;
public responded: boolean;
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>;
Expand Down Expand Up @@ -785,7 +787,6 @@ export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType>
| 'getSubcommand'
>;
public targetId: Snowflake;
public targetType: Exclude<ApplicationCommandType, ApplicationCommandType.ChatInput>;
public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>;
public inCachedGuild(): this is ContextMenuCommandInteraction<'cached'>;
public inRawGuild(): this is ContextMenuCommandInteraction<'raw'>;
Expand Down

0 comments on commit 567db60

Please sign in to comment.