UNPKG

solara-testing-beta

Version:

A modern, customizable, and lightweight Discord framework.

63 lines 2.6 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.MessageCreate, async execute(client, message) { if (message.author.bot || !message.guild || !message.channel.isTextBased()) return; const prefixes = Array.isArray(client.solaraOptions.prefix) ? client.solaraOptions.prefix : [client.solaraOptions.prefix]; const prefixUsed = prefixes.find(p => message.content.startsWith(p)); if (!prefixUsed) return; const args = message.content.slice(prefixUsed.length).trim().split(/ +/g); const commandName = args.shift()?.toLowerCase(); if (!commandName) return; const command = client.commandHandler.getCommand(commandName); if (!command || (command.type !== 'message' && command.type !== 'both')) return; if (command.developerOnly && !client.solaraOptions.developerIds?.includes(message.author.id)) { if (message.channel.isTextBased()) { await message.reply({ content: '❌ This command is restricted to developers only.' }); } return; } const ctx = { client, message, args, commandData: command, embed: undefined }; try { 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) { if ('send' in message.channel) { await message.channel.send(replyOptions); } } else { } } catch (error) { console.error(`❌ Error executing message command "${command.name}":`, error); const formattedError = await FunctionParser_1.FunctionParser.formatError(command.name, error); if (message.channel.isTextBased()) { await message.reply({ content: formattedError }).catch(() => { }); } } }, }; //# sourceMappingURL=messageCreate.js.map