Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

415
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda