58 lines
1.8 KiB
JavaScript
58 lines
1.8 KiB
JavaScript
export default {
|
|
name: "interactionCreate",
|
|
|
|
async execute(client, interaction) {
|
|
// Handle slash commands
|
|
if (interaction.isChatInputCommand()) {
|
|
const command = client.commands.get(interaction.commandName);
|
|
if (!command) return;
|
|
|
|
// Build args array from slash command options
|
|
const args = [];
|
|
if (interaction.options) {
|
|
for (const option of interaction.options.data) {
|
|
if (option.type === 7 /* CHANNEL */) {
|
|
args.push(option.channel);
|
|
} else {
|
|
args.push(String(option.value));
|
|
}
|
|
}
|
|
}
|
|
|
|
// Build a ctx object compatible with prefix command handlers
|
|
const ctx = {
|
|
isSlash: true,
|
|
interaction,
|
|
guild: interaction.guild,
|
|
author: interaction.user,
|
|
member: interaction.member,
|
|
channel: interaction.channel,
|
|
mentions: { channels: { first: () => args.find(a => typeof a === "object") } },
|
|
reply: async (opts) => {
|
|
if (interaction.replied || interaction.deferred) {
|
|
return interaction.followUp(opts);
|
|
}
|
|
return interaction.reply(opts);
|
|
},
|
|
};
|
|
|
|
try {
|
|
await command.execute(client, ctx, args);
|
|
} catch (e) {
|
|
client.logger.error(e);
|
|
const errMsg = { content: "Ein Fehler ist beim Ausführen des Befehls aufgetreten.", ephemeral: true };
|
|
if (interaction.replied || interaction.deferred) {
|
|
await interaction.followUp(errMsg);
|
|
} else {
|
|
await interaction.reply(errMsg);
|
|
}
|
|
}
|
|
}
|
|
|
|
// Handle button interactions (e.g. from add.js confirmation)
|
|
if (interaction.isButton()) {
|
|
// Button collectors handle their own interactions via awaitMessageComponent
|
|
// Nothing to do here globally
|
|
}
|
|
},
|
|
}; |