get random post from reddit nodejs code example

Example: get random reddit image link

case "pic":
    if (!args[1]) return message.channel.send("Enter a title (Be VERY specific");
    // pics was set equal to "https://www.reddit.com/r/pics.json" earlier
    snekfetch.get(pics).then(r => {
        let postTitle = args[1];
        let img = r.preview.images[0].source.url;
        let entry = r.find(post => post.title == postTitle);
        let picture = new Discord.RichEmbed()
            .setAuthor(entry.title)
            .addField(entry)
            .setImage(img);
        message.channel.send(picture);
        //message.channel.send(entry.preview.images[0].source.url);
    });
    break;

Tags:

Html Example