Welcome to bottr’s documentation!¶
Bottr is supposed to make writing bots for reddit easy. It relies on the Python Reddit API Wrapper PRAW.
Check out bottr-template for a convenient code template to start with.
Quick Start¶
The following is a quick example on how to monitor r/AskReddit for new comments. If a comment
contains the string 'banana'
, the bot prints the comment information:
import praw
import time
from bottr.bot import CommentBot
def parse_comment(comment):
"""Define what to do with a comment"""
if 'banana' in comment.body:
print('ID: {}'.format(comment.id))
print('Author: {}'.format(comment.author))
print('Body: {}'.format(comment.body))
if __name__ == '__main__':
# Get reddit instance with login details
reddit = praw.Reddit(client_id='id',
client_secret='secret',
password='botpassword',
user_agent='Script by /u/...',
username='botname')
# Create Bot with methods to parse comments
bot = CommentBot(reddit=reddit,
func_comment=parse_comment,
subreddits=['AskReddit'])
# Start Bot
bot.start()
# Run bot for 10 minutes
time.sleep(10*60)
# Stop Bot
bot.stop()
Check out Bot Account Setup to see how to get the arguments for praw.Reddit
.
Note
Please read the reddit bottiquette if you intend to run a bot that interacts with reddit, such as writing submissions/comments etc.