Python - Making a Reddit bot with PRAW Last Updated : 03 Jul, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report Reddit is a network of communities based on people’s interests. Each of these communities is called a subreddit. Users can subscribe to multiple subreddits to post, comment and interact with them. A Reddit bot is something that automatically responds to a user’s post or automatically posts things at certain intervals. This could depend on what content the users post. It can be triggered by certain key phrases and also depends on various subreddits regarding their content. In order to implement a Reddit bot, we will use the Python Reddit API Wrapper (PRAW). It allows us to login to the Reddit API to directly interact with the backend of the website. More information about this library can be found here – PRAW – Python Reddit API Wrapper. Our bot will tell the similar words for a given word. We will use the enchant module's suggest() method to find the similar words. Algorithm : Import the modules praw and enchant. Create an authorized Reddit instance with valid parameters. Choose the subreddit where the bot is to be live on. Choose a word that will trigger the bot in that subreddit. Inspect every comment in the subreddit for the trigger phrase. On finding the trigger phrase, extract the word from the comment and find its similar words using the enchant module. Reply to the comment with the similar words. Python3 1== # import the modules import praw import enchant # initialize with appropriate values client_id = "" client_secret = "" username = "" password = "" user_agent = "" # creating an authorized reddit instance reddit = praw.Reddit(client_id = client_id, client_secret = client_secret, username = username, password = password, user_agent = user_agent) # the subreddit where the bot is to be live on target_sub = "GRE" subreddit = reddit.subreddit(target_sub) # phrase to trigger the bot trigger_phrase = "! GfGBot" # enchant dictionary d = enchant.Dict("en_US") # check every comment in the subreddit for comment in subreddit.stream.comments(): # check the trigger_phrase in each comment if trigger_phrase in comment.body: # extract the word from the comment word = comment.body.replace(trigger_phrase, "") # initialize the reply text reply_text = "" # find the similar words similar_words = d.suggest(word) for similar in similar_words: reply_text += similar + " " # comment the similar words comment.reply(reply_text) Triggering the bot : The bot replying with the similar words : Comment More infoAdvertise with us Next Article Python PRAW - Blocking a redditor Y Yash_R Follow Improve Article Tags : Python Python-projects Practice Tags : python Similar Reads Python PRAW - Blocking a redditor In Reddit, a redditor is the term given to a user. Here we will see how to block a redditor as the authenticated user using PRAW. We will be using the block() method of the Redditor class to block a redditor. block() Syntax : Redditor.block() Parameter : None Returns : Nothing Example 1 : Consider t 2 min read Python PRAW â Getting the ID of a redditor In Reddit, a redditor is the term given to a user. Each and every redditor has a unique ID provided to them. Here we will see how to fetch the ID of a redditor. We will be using the id attribute of the Redditor class to fetch the ID of a redditor. Example 1 : Consider the following redditor : The us 2 min read Python PRAW - Upvoting a comment in Reddit In Reddit, we can post a comment to any submission, we can also comment on a comment to create a thread of comments. We can either upvote or downvote a comment. Here we will see how to upvote a comment using PRAW. We will be using the upvote() method of the Comment class to upvote a comment. upvote 2 min read Python PRAW - Friending a redditor In Reddit, a redditor is the term given to a user. Reddit gives us the functionality to add a redditor as a friend with the authenticated user. Here we will see how to befriend a redditor. We will be using the friend() method of the Redditor class to befriend a redditor. friend() Syntax : Redditor.f 2 min read Python PRAW - Getting the body of a comment in Reddit In Reddit, we can post a comment to any submission, we can also comment on a comment to create a thread of comments. Every comment have some textual information in it which is called the body of the comment. Here we will see how to fetch the body of a comment using PRAW. We will be using the body at 2 min read Python PRAW â Getting the link karma of a redditor In Reddit, a redditor is the term given to a user. Reddit karma is the score you get for posting and commenting on Reddit. Here we will see how to fetch the karma obtained by posting submissions on Reddit by a redditor. We will be using the link_karma attribute of the Redditor class to fetch the lin 2 min read Like