-2

This is the data i want to make my bot able to fetch. I'm not really good and quite new to the whole node-fetch thing. enter image description here

This is the code i tried to use, however the "joke" it only returns undefined.

let url = "https://icanhazdadjoke.com/slack";
        let joke;
        let permLink;
        fetch(url).then(res => res.json()).then(data => {
            joke = data.attachments.text;


            let embed = new MessageEmbed()
                .setAuthor("Random Dadjoke", message.guild.iconURL)
                .setColor(red_light)
                .addField("Joke:", joke)
                .addField("Permenent Link:","TEST")
                .addField("TEST:", "TEST")
                .setDescription("Here's your random joke :D")

            message.channel.send(embed);
            console.log("dadjoke.js");
        });
Andresen
  • 29
  • 2

1 Answers1

0

this is why there is an array in the json, to recover for example the text you have to do this:

data.attachments[0].text

instead of that

data.attachments.text