mirror of
https://github.com/discordjs/discord.js.git
synced 2026-05-30 07:30:09 +00:00
67 lines
2.2 KiB
JavaScript
67 lines
2.2 KiB
JavaScript
'use strict';
|
|
|
|
const Action = require('./Action');
|
|
const ButtonInteraction = require('../../structures/ButtonInteraction');
|
|
const CommandInteraction = require('../../structures/CommandInteraction');
|
|
const SelectMenuInteraction = require('../../structures/SelectMenuInteraction');
|
|
const { Events, InteractionTypes, MessageComponentTypes } = require('../../util/Constants');
|
|
|
|
let deprecationEmitted = false;
|
|
|
|
class InteractionCreateAction extends Action {
|
|
handle(data) {
|
|
const client = this.client;
|
|
|
|
// Resolve and cache partial channels for Interaction#channel getter
|
|
this.getChannel(data);
|
|
|
|
let InteractionType;
|
|
switch (data.type) {
|
|
case InteractionTypes.APPLICATION_COMMAND:
|
|
InteractionType = CommandInteraction;
|
|
break;
|
|
case InteractionTypes.MESSAGE_COMPONENT:
|
|
switch (data.data.component_type) {
|
|
case MessageComponentTypes.BUTTON:
|
|
InteractionType = ButtonInteraction;
|
|
break;
|
|
case MessageComponentTypes.SELECT_MENU:
|
|
InteractionType = SelectMenuInteraction;
|
|
break;
|
|
default:
|
|
client.emit(
|
|
Events.DEBUG,
|
|
`[INTERACTION] Received component interaction with unknown type: ${data.data.component_type}`,
|
|
);
|
|
return;
|
|
}
|
|
break;
|
|
default:
|
|
client.emit(Events.DEBUG, `[INTERACTION] Received interaction with unknown type: ${data.type}`);
|
|
return;
|
|
}
|
|
|
|
const interaction = new InteractionType(client, data);
|
|
|
|
/**
|
|
* Emitted when an interaction is created.
|
|
* @event Client#interactionCreate
|
|
* @param {Interaction} interaction The interaction which was created
|
|
*/
|
|
client.emit(Events.INTERACTION_CREATE, interaction);
|
|
|
|
/**
|
|
* Emitted when an interaction is created.
|
|
* @event Client#interaction
|
|
* @param {Interaction} interaction The interaction which was created
|
|
* @deprecated Use {@link Client#interactionCreate} instead
|
|
*/
|
|
if (client.emit('interaction', interaction) && !deprecationEmitted) {
|
|
deprecationEmitted = true;
|
|
process.emitWarning('The interaction event is deprecated. Use interactionCreate instead', 'DeprecationWarning');
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = InteractionCreateAction;
|