link source reddit.com/r/redditbot/comments/6qjvjq/how_to_build_a_simple_reddit_bot_that_responds_to/ def create_r/RedditBot(reddit): “””Creates a Reddit bot from a subreddit URL and the URL parameters.
This is the same as bot.py but with a few additional steps: First, add the reddit api key and API Secret (or any other key you need to create a new one) to the bot’s credentials.
Second, we must create a Reddit account with the username r/all.
Third, create a URL to the subreddit.
Finally, create the bot.
“”” submission = submission.find_by_title(‘/new/submission’) submission.add_comment(‘You made it to the top of this list!’) “
“” bot = RedditBot(subreddit_name, api_key=api_key, subreddit_secret=subreddit) # Create a new Reddit account bot.create_profile() # Create the URL to a subreddit bot.get_url() # Get the subreddit name bot.subreddit = ‘r/ALL’ # Get subreddit username bot.username = ‘USERNAME’ # Set the API Secret bot.api_secret = ‘SSH_API_KEY’ # The Reddit API key bot.domain = ‘reddit.com’ # Add the API Key to the URL def create(submission): “””This creates a new submission and returns the link with the URL it’s pointing to.
“”” submission = submission.find_by_title(‘/new/submission’) submission.add_comment(‘You made it to the top of this list!’)
return submission def get_url(url): “””Returns a link to the submission’s full URL.””” url = url.lower() # Replace the URL with the new submission’s URL return submission.url # Get all comments on a subreddit submission.comments = [submission.comments, submission.posts] # Add new comments to the list submissions.add(submissions.get(submitted_id)) submissions.get([submitted.id]) # Get comments from a specific subreddit submission = Submission(subdomain=’reddit.org’) if __name__ == ‘__main__’: reddit = Reddit(subsite_name=’r/All’, api_name=reddit)