Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

578
Visualizações
discord.js v13 - Cannot use Interaction Options

For the past while, I've been trying to make an "Eval" command using Slash Commands.
I have a system in place that goes along with my Command Handler, however, it's specifically the "Eval" command that's causing issues.

I'm currently using @discordjs/builders, however, it's not helping with this.
This is how the Slash Command is built:

slash: new SlashCommandBuilder()
        .setName("eval")
        .setDescription("Evaluates JavaScript code.")
        .addStringOption(option => option.setName("code").setDescription("Your JavaScript code.").setRequired(true)),

In Discord, the "code" option doesn't even appear. When I try to run the command by running:

/eval ```js
console.log("Hello World");

I get an error saying Cannot read property "replace" of null
Here's the script for the Slash Command:

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.`);
    }
}

I've tried debugging for a while, and I am extremely confused. Thanks for any help you can provide!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

So, I realized I used the wrong variable within my Command Handler, which broke the Slash Commands.

Oops!

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda