From b9ad74e89422d3275fd03c55ad14dffb57fe78b8 Mon Sep 17 00:00:00 2001 From: UltraLion <49597041+UltraLionfr@users.noreply.github.com> Date: Sat, 5 Nov 2022 23:05:15 +0100 Subject: [PATCH] Create interactionCreate.js --- events/interactionCreate.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 events/interactionCreate.js diff --git a/events/interactionCreate.js b/events/interactionCreate.js new file mode 100644 index 0000000..27e56bf --- /dev/null +++ b/events/interactionCreate.js @@ -0,0 +1,33 @@ +const client = require("../index"); + +client.on("interactionCreate", async (interaction) => { + // Slash Command Handling + if (interaction.isChatInputCommand()) { + await interaction.deferReply({ ephemeral: false }).catch(() => { }); + + const cmd = client.slashCommands.get(interaction.commandName); + if (!cmd) + return interaction.followUp({ content: "An error has occurred " }); + + const args = []; + + for (let option of interaction.options.data) { + if (option.type === "SUB_COMMAND") { + if (option.name) args.push(option.name); + option.options?.forEach((x) => { + if (x.value) args.push(x.value); + }); + } else if (option.value) args.push(option.value); + } + interaction.member = interaction.guild.members.cache.get(interaction.user.id); + + cmd.run(client, interaction, args); + } + + // Context Menu Handling + if (interaction.isContextMenuCommand()) { + await interaction.deferReply({ ephemeral: false }); + const command = client.slashCommands.get(interaction.commandName); + if (command) command.run(client, interaction); + } +});