Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

328
Views
JavaScript Discord Embed is not reading certain Embed.set commands. (Discord meme bot) [[Solved]]

I'm trying to make a discord meme bot (in this case, cute animal pictures bot). The code is this; code screenshot

But when I use the command in discord, the reply only shows the description, not the color or image.

discord screenshot

What am I doing wrong?

here's the code of the command file for copy paste;

const { MessageEmbed } = require('discord.js');
const randomPuppy = require('random-puppy');

module.exports = {
    name: 'cute',
    description: 'Embeds pictures pulled from listed subreddits',
    execute(message, args, Discord){
        let reddit = [
            "aww",
            "puppies",
            "toebeans"
        ]

        let subreddit = reddit[Math.floor(Math.random()*reddit.length -1)];

        const cuteEmbed = new MessageEmbed()
        .setDescription("Some cute animals to blow away your anxieties!");

        randomPuppy(subreddit).then(url => {
            console.log(url);
            const cuteurl = url;
            
            cuteEmbed.setColor('#91B2C7');
            cuteEmbed.setImage('${cuteurl}');
            });

            message.channel.send(cuteEmbed);
        }
    }

please help :'(

Edit: BACK TICKS. GODDAMN BACK TICKS. I'm using a new code so idk if using back ticks would've fixed it, but that's one mistake in the code; I didn't use backticks for interpolation.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The method randomPuppy() is asynchronous. Meaning that you need to wait for the promise to send the embed message. In your current code, you send the embed without waiting for the request to complete.

You have to change your code from:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
});

message.channel.send(cuteEmbed);

To:

randomPuppy(subreddit).then(url => {
  cuteEmbed.setColor('#91B2C7');
  cuteEmbed.setImage('${url}');
  message.channel.send(cuteEmbed); //Send the embed once the request is completed.
});
about 4 years ago · Juan Pablo Isaza Report

0

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        });

        message.channel.send(cuteEmbed);
    }

You are trying to send the embed even the request is not finished, all you need to do is to put the message.channel.send() inside of .then

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}');
        message.channel.send(cuteEmbed);
        });
    }

And I noticed something that you missed type one of the keypress you should type backquote instead of quote, so after editing your code. You just need to edit the quote to backquote:

    randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url;
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage('${cuteurl}'); //This is the part you need to change it
        message.channel.send(cuteEmbed);
        });
    }

To this:

   randomPuppy(subreddit).then(url => {
        console.log(url);
        const cuteurl = url; //image should call this after changing it
        
        cuteEmbed.setColor('#91B2C7');
        cuteEmbed.setImage(`${cuteurl}`); //To this, to call your cuteurl
        message.channel.send(cuteEmbed);
        });
    }
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!