feat(Interaction): add .commandType property to CommandInteraction and AutocompleteInteraction (#7357)

This commit is contained in:
Matthew1177
2022-01-30 03:56:38 -08:00
committed by GitHub
parent fbb1d0328b
commit 567db60475
5 changed files with 18 additions and 12 deletions

View File

@@ -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}

View File

@@ -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}

View File

@@ -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;
}
/**

View File

@@ -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;
}
/**

View File

@@ -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;
@@ -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'>;
@@ -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'>;