mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-18 12:33:30 +01:00
feat(Interaction): add .commandType property to CommandInteraction and AutocompleteInteraction (#7357)
This commit is contained in:
@@ -30,6 +30,12 @@ class AutocompleteInteraction extends Interaction {
|
|||||||
*/
|
*/
|
||||||
this.commandName = data.data.name;
|
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
|
* Whether this interaction has already received a response
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|||||||
@@ -33,6 +33,12 @@ class CommandInteraction extends Interaction {
|
|||||||
*/
|
*/
|
||||||
this.commandName = data.data.name;
|
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
|
* Whether the reply to this interaction has been deferred
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
|
|||||||
@@ -26,13 +26,6 @@ class ContextMenuCommandInteraction extends CommandInteraction {
|
|||||||
* @type {Snowflake}
|
* @type {Snowflake}
|
||||||
*/
|
*/
|
||||||
this.targetId = data.data.target_id;
|
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ class Interaction extends Base {
|
|||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isChatInputCommand() {
|
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}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isContextMenuCommand() {
|
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}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isUserContextMenuCommand() {
|
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}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
isMessageContextMenuCommand() {
|
isMessageContextMenuCommand() {
|
||||||
return this.isContextMenuCommand() && this.targetType === ApplicationCommandType.Message;
|
return this.isContextMenuCommand() && this.commandType === ApplicationCommandType.Message;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
3
packages/discord.js/typings/index.d.ts
vendored
3
packages/discord.js/typings/index.d.ts
vendored
@@ -326,6 +326,7 @@ export abstract class CommandInteraction<Cached extends CacheType = CacheType> e
|
|||||||
public channelId: Snowflake;
|
public channelId: Snowflake;
|
||||||
public commandId: Snowflake;
|
public commandId: Snowflake;
|
||||||
public commandName: string;
|
public commandName: string;
|
||||||
|
public commandType: ApplicationCommandType;
|
||||||
public deferred: boolean;
|
public deferred: boolean;
|
||||||
public ephemeral: boolean | null;
|
public ephemeral: boolean | null;
|
||||||
public replied: boolean;
|
public replied: boolean;
|
||||||
@@ -705,6 +706,7 @@ export class AutocompleteInteraction<Cached extends CacheType = CacheType> exten
|
|||||||
public channelId: Snowflake;
|
public channelId: Snowflake;
|
||||||
public commandId: Snowflake;
|
public commandId: Snowflake;
|
||||||
public commandName: string;
|
public commandName: string;
|
||||||
|
public commandType: ApplicationCommandType.ChatInput;
|
||||||
public responded: boolean;
|
public responded: boolean;
|
||||||
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
public options: Omit<CommandInteractionOptionResolver<Cached>, 'getMessage'>;
|
||||||
public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>;
|
public inGuild(): this is AutocompleteInteraction<'raw' | 'cached'>;
|
||||||
@@ -785,7 +787,6 @@ export class ContextMenuCommandInteraction<Cached extends CacheType = CacheType>
|
|||||||
| 'getSubcommand'
|
| 'getSubcommand'
|
||||||
>;
|
>;
|
||||||
public targetId: Snowflake;
|
public targetId: Snowflake;
|
||||||
public targetType: Exclude<ApplicationCommandType, ApplicationCommandType.ChatInput>;
|
|
||||||
public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>;
|
public inGuild(): this is ContextMenuCommandInteraction<'raw' | 'cached'>;
|
||||||
public inCachedGuild(): this is ContextMenuCommandInteraction<'cached'>;
|
public inCachedGuild(): this is ContextMenuCommandInteraction<'cached'>;
|
||||||
public inRawGuild(): this is ContextMenuCommandInteraction<'raw'>;
|
public inRawGuild(): this is ContextMenuCommandInteraction<'raw'>;
|
||||||
|
|||||||
Reference in New Issue
Block a user