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

448
Visualizações
Using async() functions in eval() - discord.js
  • Recently, I tried the eval command in my bot using 'await' but since await is valid in async functions, I made the following aeval command.
  • The problem here is, it only returns undefined for everything I eval.
const { Base } = require("../../../lib/base");
const { inspect } = require("util");

module.exports = new Base({
    name: "aeval",
    description: "Owner only command to evaluate an asynchronous javascript code",
    async execute({ client, message, args }) {
        let script = args.join(" ");
        let evaled;
        let hrDiff;
        try {
            const hrTime = process.hrtime();
            evaled = await eval(`(async() => {${script}})()`);
            hrDiff = process.hrtime(hrTime);
            evaled = inspect(evaled);
            await message.reply(
                `Executed in \`${hrDiff[1] / 1000000}\` ms.\n\`\`\`js\n${inspect(
                    evaled
                )}\n\`\`\``
            );
        } catch (error) {
            console.log(error);
            message.reply(`Error Occurred:\n\`\`\`js\n${error}\n\`\`\``);
        }
    },
});
about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can try it like this:

evaled = await eval('async () => code')()

This moves the function outside of the eval so you can successfully call it in a async context.

Note that using eval is a bad idea and allows unlimited control over your server, including wiping the database or deleting the bot itself. Be very very careful, and consider using other options to do the server administration you require.

about 4 years ago · Santiago Trujillo 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