import { Command, devOnly } from "@voidy/framework"; import { MessageFlags, SlashCommandBuilder } from "discord.js"; export default new Command({ id: "exec", use: [devOnly], data: new SlashCommandBuilder() .setName("exec") .setDescription("Evaluates the user-supplied JavaScript code, has access to standard command context information.") .addStringOption((option) => option.setName("code").setDescription("The code to evaluate.").setRequired(true), ), execute: async (ctx) => { const { interaction } = ctx; const code = interaction.options.getString("code", true); try { const fn = new Function("ctx", "interaction", "client", code); const result = await fn(ctx, interaction, ctx.client); const output = typeof result === "string" ? result : Bun.inspect(result, { depth: 2 }); await interaction.reply({ content: `\`\`\`\n${output.slice(0, 1900)}\n\`\`\``, flags: [MessageFlags.Ephemeral], }); } catch (err) { await interaction.reply({ content: `\`\`\`\n${err}\n\`\`\``, flags: [MessageFlags.Ephemeral], }); } } });