UNPKG

solara-testing-beta

Version:

A modern, customizable, and lightweight Discord framework.

55 lines 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const discord_js_1 = require("discord.js"); const FunctionParser_1 = require("../core/FunctionParser"); exports.default = { name: discord_js_1.Events.InteractionCreate, async execute(client, interaction) { if (!interaction.isCommand() || !interaction.guildId) return; const command = client.commandHandler.getCommand(interaction.commandName); if (!command || (command.type !== 'interaction' && command.type !== 'both') || !command.slash) return; if (command.developerOnly && !client.solaraOptions.developerIds?.includes(interaction.user.id)) { await interaction.reply({ content: '❌ This command is restricted to developers only.', ephemeral: true }); return; } const args = interaction.options.data.map(opt => String(opt.value ?? '')); const ctx = { client, interaction: interaction, args, commandData: command, embed: undefined }; try { await interaction.deferReply({ ephemeral: ctx.ephemeral ?? false }); const result = await client.functionParser.parse(command.code, ctx); const replyOptions = {}; const content = result.trim(); if (content) { replyOptions.content = content; } if (ctx.embed && (ctx.embed.data.title || ctx.embed.data.description || ctx.embed.data.fields?.length)) { replyOptions.embeds = [ctx.embed]; } if (replyOptions.content || replyOptions.embeds) { await interaction.editReply(replyOptions); } else { await interaction.editReply({ content: '✅ Command executed.' }); } } catch (error) { console.error(`❌ Error executing interaction command "${command.name}":`, error); const formattedError = await FunctionParser_1.FunctionParser.formatError(command.name, error); if (interaction.deferred || interaction.replied) { await interaction.editReply({ content: formattedError, embeds: [] }).catch(() => { }); } else { await interaction.reply({ content: formattedError, ephemeral: true }).catch(() => { }); } } }, }; //# sourceMappingURL=interactionCreate.js.map