loading...

Push new reddit post to Discord Channel

gfjaru profile image Umbara ・1 min read

I found a Python library called praw or The Python Reddit API Wrapper, I've done some work with this library a while ago for creating simple bot. In this case, I think about watching a subreddit from Discord without opening browser.

I've made few codes, but its limited to fetch new post from subreddit. I am not a guy with educate skill but I'll make this simple and clear.

GitHub logo gfjaru / reddit-watcher

👀 Grab latest post from subreddit

reddit-watcher

👀 have an eyes on subreddit, always get latest post.

Installation

(run locally) set environment variable for:

  • DISCORD_WEBHOOK_URL
  • DISCORD_WEBHOOK_NAME
  • DISCORD_WEBHOOK_AVATAR
  • REDDIT_CLIENT_ID
  • REDDIT_CLIENT_SECRET
  • REDDIT_USERNAME
  • REDDIT_PASSWORD
  • REDDIT_SUBREDDIT

Then install dependencies, just type

pip install -r requirements.txt

Run the app.

Heroku

Deploy

***idk how to deal with this, run worker manually after deploying, go to heroku app > resource > worker


Originally created for grabbing meme from r/Hololive.




The logic is quite simple, run a loop within checking latest post, then send post request to discord with their webhook integration, so I can watch every new post that user posted on the subreddit. (detailed code included)

Hosting

We don't want to run this locally 24/7 because of electricity bill, so we need a plaform that can run any script as workers.

In this case, we need save $ at any cost. We choose Heroku (Free tier) and we got hours that enough for one month (1 dyno).

Deploy yourself, there is a button for instant deploy.

EOL

Well, this originally was created for fetching latest post from r/Hololive, but it fits for any subreddit I think.

Posted on by:

gfjaru profile

Umbara

@gfjaru

student @ telkom university

Discussion

pic
Editor guide