Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

444
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda