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

416
Views
Random Meme Command (discord.js v13)

I'm trying to make random meme command that sends meme's from r/reddit, but i have an error

const { MessageEmbed } = require("discord.js");
const fetch = require("node-fetch");

module.exports = {
  name: "meme",
  description: "This command sends you random memes",
  category: "fun",
  example: ["x!meme"],
  callback: async ({ message }) => {
    try {
      const url = await fetch("https://www.reddit.com/r/memes/random/.json");
      const random = await url.json();

      const embed = new MessageEmbed()
        .setTitle(`Random Meme | ${random[0].data.children.data.title}`)
        .setImage(random[0].data.children.data.url)
        .setColor("#FF00A6");
        .setFooter("Prefix x! | Random Meme Generator")

      await message.channel.send({ embeds: [embed] });
    } catch (err) {
      console.log(err);
    }
  },
};

I don't know why but I get this error

On the older version (discord.js v12) it worked normally

TypeError: Cannot read properties of undefined (reading 'title')
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

After visiting the link, it seems like random[0].data.children is an array. Get the first element from it:

.setTitle(`Random Meme | ${random[0].data.children[0].data.title}`)

You will need to do the same with the image:

.setImage(random[0].data.children[0].data.url)
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!