Durante el último tiempo, he estado tratando de hacer un comando "Eval" usando Slash Commands.
Tengo un sistema implementado que va junto con mi controlador de comandos, sin embargo, es específicamente el comando "Eval" el que está causando problemas.
Actualmente estoy usando @discordjs/builders , sin embargo, no está ayudando con esto.
Así es como se construye el comando Slash:
slash: new SlashCommandBuilder() .setName("eval") .setDescription("Evaluates JavaScript code.") .addStringOption(option => option.setName("code").setDescription("Your JavaScript code.").setRequired(true)),En Discord ni siquiera aparece la opción de "código". Cuando intento ejecutar el comando ejecutando:
/eval ```js console.log("Hello World"); Recibo un error que dice Cannot read property "replace" of null
Aquí está el script para el comando Slash:
runSlash: async (interaction, bot) => { if (interaction.user.id !== interaction.guild.ownerId) { interaction.reply("You are not allowed to do this."); return bot.commandLog(`${msg.author} attempted to use the EVAL command, but was not Atelo.`); } const toEval = interaction.options.getString("code"); console.log(interaction.options); /* this is what ^^^ returns: CommandInteractionOptionResolver { _group: null, _subcommand: null, _hoistedOptions: [] } */ console.log(interaction.options.getString("code")); // Also returns null const toRemove = /^(```js)|(```)$/gi; const evalEmbed = new MessageEmbed(); try { const evalled = eval(toEval.replace(toRemove, '')); evalEmbed.setTitle("Evaluation Successful"); evalEmbed.addFields({ name: "Output", value: "```js\n" + evalled + "\n```" }); evalEmbed.setFooter(interaction.guild.name, interaction.guild.iconURL()); evalEmbed.setTimestamp(); } catch (err) { evalEmbed.setTitle("Evaluation Failed"); evalEmbed.addFields({ name: "Output", value: "```js\n" + err + "\n```" }); evalEmbed.setFooter(interaction.guild.name, interaction.guild.iconURL()); evalEmbed.setTimestamp(); } interaction.reply({ embeds: [evalEmbed] }); return bot.commandLog(`${msg.author} successfully used the EVAL command.`); } }He intentado depurar durante un tiempo y estoy extremadamente confundido. ¡Gracias por cualquier ayuda que usted nos pueda proporcionar!
Entonces, me di cuenta de que usé la variable incorrecta dentro de mi controlador de comandos, lo que rompió los comandos de barra.
¡Ups!