diff --git a/src/client/actions/InteractionCreate.js b/src/client/actions/InteractionCreate.js index 9b6dc7d2a80a..07470224c1e9 100644 --- a/src/client/actions/InteractionCreate.js +++ b/src/client/actions/InteractionCreate.js @@ -5,7 +5,7 @@ const ButtonInteraction = require('../../structures/ButtonInteraction'); const CommandInteraction = require('../../structures/CommandInteraction'); const ContextMenuInteraction = require('../../structures/ContextMenuInteraction'); const SelectMenuInteraction = require('../../structures/SelectMenuInteraction'); -const { Events, InteractionTypes, MessageComponentTypes } = require('../../util/Constants'); +const { Events, InteractionTypes, MessageComponentTypes, ApplicationCommandTypes } = require('../../util/Constants'); let deprecationEmitted = false; @@ -19,10 +19,20 @@ class InteractionCreateAction extends Action { let InteractionType; switch (data.type) { case InteractionTypes.APPLICATION_COMMAND: - if (typeof data.data.target_id === 'undefined') { - InteractionType = CommandInteraction; - } else { - InteractionType = ContextMenuInteraction; + switch (data.data.type) { + case ApplicationCommandTypes.APPLICATION_COMMAND: + InteractionType = CommandInteraction; + break; + case ApplicationCommandTypes.USER: + case ApplicationCommandTypes.MESSAGE: + InteractionType = ContextMenuInteraction; + break; + default: + client.emit( + Events.DEBUG, + `[INTERACTION] Received application command interaction with unknown type: ${data.data.type}`, + ); + return; } break; case InteractionTypes.MESSAGE_COMPONENT: diff --git a/src/structures/ContextMenuInteraction.js b/src/structures/ContextMenuInteraction.js index 72622bb9e8b3..5bb8a66409b7 100644 --- a/src/structures/ContextMenuInteraction.js +++ b/src/structures/ContextMenuInteraction.js @@ -2,7 +2,7 @@ const BaseCommandInteraction = require('./BaseCommandInteraction'); const CommandInteractionOptionResolver = require('./CommandInteractionOptionResolver'); -const { ApplicationCommandOptionTypes } = require('../util/Constants'); +const { ApplicationCommandOptionTypes, ApplicationCommandTypes } = require('../util/Constants'); /** * Represents a context menu interaction. @@ -12,7 +12,7 @@ class ContextMenuInteraction extends BaseCommandInteraction { constructor(client, data) { super(client, data); /** - * The target of the interaction, parsed into an option + * The target of the interaction, parsed into options * @type {CommandInteractionOptionResolver} */ this.options = new CommandInteractionOptionResolver(this.client, this.resolveContextMenuOptions(data.data)); @@ -22,6 +22,12 @@ class ContextMenuInteraction extends BaseCommandInteraction { * @type {Snowflake} */ this.targetId = data.data.target_id; + + /** + * The type of the target of the interaction; either USER or MESSAGE + * @type {ApplicationCommandType} + */ + this.targetType = ApplicationCommandTypes[data.data.type]; } /** diff --git a/typings/index.d.ts b/typings/index.d.ts index 1cf1c8fe9c3f..c0806f2e1030 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -581,6 +581,7 @@ export class CommandInteractionOptionResolver { export class ContextMenuInteraction extends BaseCommandInteraction { public options: CommandInteractionOptionResolver; public targetId: Snowflake; + public targetType: Exclude; private resolveContextMenuOptions(data: APIApplicationCommandInteractionData): CommandInteractionOption[]; }