Introduction: Reddit Reply Bot

The purpose of this instruction set is to build a simple Reddit bot. A Reddit bot is a program which scans posts/comments on Reddit, and can react to the information it collects. This can be important for many reasons, like getting familiar with the Reddit API (Application Programming Interface) using PRAW or to easily reply to multiple posts at once. In order to compete this, you must have a Reddit account, should have some familiarity with coding in Python and need to have your system PATH variable for Python set up so you can compile Python at the command line or terminal. If none of that makes sense to you, you are probably not prepared for this tutorial. If these steps are done correctly, this should be finished in no more than 30 minutes. Good luck and I hope you find this informative, happy botting!

Step 1: Login and Create Personal App

First login into Reddit or make an account and go to https://ssl.reddit.com/prefs/apps/ to create a personal app.

Step 2: Create App

Name the app and make sure the script circle is filled, also add a name and description to app (can be anything), you can use a random url for the redirect url such as http://localhost:

Step 3: App Screen

Once you have created the app, you are given a ‘personal use script’ and ‘secret’, make sure you remember what those are, very important.

Step 4: Make RedditBot Folder and Open CMD

Create a new folder on your desktop called, “RedditBot” and open up cmd or terminal. Then, go to it's directory using cd /Users/Admin/Desktop/RedditBot. Also make sure to replace Admin with your user account.

Step 5: Pip Install PRAW

Then, type the command python -m pip install praw, skip if you already have installed.

Step 6: Drag Praw.ini File Into Folder

Once you’ve done that, go to where you installed Python and type in finder praw.ini, take that file and drag it into your RedditBot folder. Most likely Python will be installed under Users and AppData in the C drive.

Step 7: Make a New Python File

Open up Python IDLE or equivalent text editor and create a new file called reddit_bot.py. Make sure to save it in your RedditBot folder you made in step 4.

Step 8: Paste the Code

After you created that file, paste this code with minor adjustments. Change the username and password fields to your own, the user_agent can be anything, the client_id is your personal use script from step 3, and client_secret is your secret from step 3. Also, when pasting this code make sure the indentations are the same as the picture above. Also make sure that each variable you enter is in the quotations.

#!/usr/bin/python
import praw

#Enter your correct Reddit information into the variable below

userAgent = 'Enter Bot name'

cID = 'Enter your personal use script'

cSC= 'Enter you client secret'

userN = 'Enter your Reddit username'

userP ='Enter your Reddit password'

numFound = 0

reddit = praw.Reddit(user_agent=userAgent, client_id=cID, client_secret=cSC, username=userN, password=userP)

subreddit = reddit.subreddit('weather') #any subreddit you want to monitor

bot_phrase = 'Aw shucks, looks like I am staying in >:(' #phrase that the bot replies with

keywords = {'Cold', 'chicago', 'polar', 'vortex'} #makes a set of keywords to find in subreddits

for submission in subreddit.hot(limit=10): #this views the top 10 posts in that subbreddit

n_title = submission.title.lower() #makes the post title lowercase so we can compare our keywords with it.

for i in keywords: #goes through our keywords

if i in n_title: #if one of our keywords matches a title in the top 10 of the subreddit

numFound = numFound + 1

print('Bot replying to: ') #replies and outputs to the command line

print("Title: ", submission.title)

print("Text: ", submission.selftext)

print("Score: ", submission.score)

print("---------------------------------")

print('Bot saying: ', bot_phrase)

print()

submission.reply(bot_phrase)

if numFound == 0:

print()

print("Sorry, didn't find any posts with those keywords, try again!")

Step 9: Run Your Code!

Then save the file in your RedditBot folder and run it on cmd with pythonreddit_bot.py

Step 10: And That's It!

Now you should have a working Reddit bot, capable of scanning through your favorite subreddit and responding automatically with a desired phrase. You can also use this code as a good starting point for other Reddit bot ideas, which could be anything from converting temperatures, to replying to people with cat pictures. Thanks for reading through, hope this was useful and good luck on any future projects.