- I recently attempted to utilize the
eval
command in my bot with the use of 'await'. However, since await is only valid in async functions, I created a new command calledaeval
. - The issue I am facing is that the
aeval
command is returningundefined
for all evaluations.
const { Base } = require("../../../lib/base");
const { inspect } = require("util");
module.exports = new Base({
name: "aeval",
description: "This command is exclusively for owners to evaluate 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(`An error occurred:\n\`\`\`js\n${error}\n\`\`\``);
}
},
});