Skip to content

Memes, Cats & Nature

Rick Groot edited this page Dec 24, 2020 · 2 revisions

Reddit pictures

This functionality is based on the reddit API. With this API you can get random images from any subreddit, and post them in your chat with discord.js.

Memes

//meme, this command will get you a random meme that had more then 1000 upvotes on reddit. Memes will be chosen randomly, thanks to the reddit API. The request will be of one of the following subreddits:

  • dankmemes
  • HolUp
  • blursedimages
  • Unexpected

Cats

//cat, this command wil send you a random image from reddit of a cat. Cats will be chosen randomly from a specified subreddit listed below. All returned cat images will have a minimum of 500 upvotes on reddit.

  • CatsAreAssholes
  • tuckedinkitties
  • MEOW_IRL
  • cats
  • kittens
  • blurrypicturesofcats

Nature

//nature, this command will send a nature picture in your chat. All images have at least 1000 upvotes on reddit and will be chosen randomly via the reddit API. The nature command contains images of the following subreddits:

  • NatureIsFuckingLit
  • pics
  • EarthPorn
  • natureporn

How it works

All of the requests above use the reddit API. This API will send you a lot of information about anything on reddit, or in this case it will give the bot information about good reddit posts.

            const subReddits = [
                'dankmemes',
                'HolUp',
                'blursedimages',
                'Unexpected'
            ];

The subreddits get defined first. One of these will be passed through to another function, which will get the data. The subreddit name will be wrapped inside a link, because the data gets requested via a link. Data will be sent back in JSON format, and is put inside a message that's send to the text channel.

                let permalink = content[0].data.children[0].data.permalink; // create message variables
                let postUrl = `https://reddit.com${permalink}`;
                let postImage = content[0].data.children[0].data.url;
                let postTitle = content[0].data.children[0].data.title;
                let postUpvotes = content[0].data.children[0].data.ups;
                let postNumComments = content[0].data.children[0].data.num_comments;
                let isVideo = content[0].data.children[0].data.is_video;

This is a small example of how the message is set up. When the content type is a video or when the post is empty or has too little upvotes, the function will be called again. This process will repeat until there is a suitable post.

All code can be found in this document.

Clone this wiki locally