Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

76
Vistas
Promise { <pending> } LOG

i was making meme.js file/command and i got this error idk how to resolve this problem, Can you help me?

so this is my code:

const fetch = require('node-fetch');
const randomPuppy = require("random-puppy");

module.exports = {
    name: "meme",
    description: "Sends an epic meme",
    execute(message) {
        const subReddits = ["dankmeme", "meme", "me_irl"];
        const random = subReddits[Math.floor(Math.random() * subReddits.length)];

        const img = await randomPuppy(random);
        console.log(img)
        const memeEmbed = new MessageEmbed()
            .setColor("#fa0557")
          //  .setImage(`${img}`)
            .setTitle(`From /r/${random}`)
            .setURL(`https://reddit.com/r/${random}`);

        message.channel.send({ embeds: [memeEmbed] });
    }
}

And this is the log i got:

Promise { <pending> }
7 months ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The posted code throws a syntax error that await can only be used inside an async function - which `module.exports.execute' has not been declared as.

Try declaring execute as an async function

module.exports = {
    name: "meme",
    description: "Sends an epic meme",
    async execute(message) { . . .

If the log in the post does show

Promise { <pending> }

on the console, please update the post with necessary code to reproduce the problem.

7 months ago · Juan Pablo Isaza Denunciar

0

Your code as shown will not run. You show await randomPuppy(random), but await is NOT allowed there because it's not inside an async function. So, I suspect that your real code does not have the await and that's why you show Promise { <pending> } in your console. You have to use either await or .then() on the promise that randomPuppy(random) returns.

If I fix your code so that it will run by adding async to the execute() definition, then the console.log(img) actually works just fine:

const randomPuppy = require("random-puppy");

module.exports = {
    name: "meme",
    description: "Sends an epic meme",
    async execute(message) {
        const subReddits = ["dankmeme", "meme", "me_irl"];
        const random = subReddits[Math.floor(Math.random() * subReddits.length)];

        const img = await randomPuppy(random);
        console.log(img)
    }
}

module.exports.execute().then(result => {
    console.log(result);
}).catch(err => {
    console.log(err);
});

And, I get in my console this:

http://imgur.com/FFkL628.gif
done

So, my conclusion is that the code you posted in your question is not the code you're actually running. This code shown here will work just fine.

7 months ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.