Comment Bot¶
-
class
bottr.bot.
CommentBot
(reddit: praw.reddit.Reddit, name: str = 'CommentBot', func_comment: typing.Callable[[praw.models.reddit.comment.Comment], NoneType] = None, func_comment_args: typing.List = None, subreddits: typing.Iterable = None, n_jobs=4)[source]¶ This bot listens to incoming comments and calls the provided method
func_comment
asfunc_comment(comment, *func_comment_args)
for eachcomment
that is submitted in the givensubreddits
.Creates a bot that listens to comments in a list of subreddits and calls a given function on each new comment.
Parameters: - reddit –
praw.Reddit
instance. Check Bot Account Setup on how to create it. - name – Bot name
- func_comment – Comment function. It needs to accept a
praw.models.Comment
object and may take more arguments. For each comment created insubreddits
, apraw.models.Comment
object and allfun_comments_args
are passed tofunc_comment
as arguments. - func_comment_args – Comment function arguments.
- subreddits – List of subreddit names. Example:
['AskReddit', 'Videos', ...]
- n_jobs – Number of parallel threads that are started when calling
start()
to process in the incoming comments.
Example usage:
# Write a parsing method def parse(comment): if 'banana' in comment.body: comment.reply('This comment is bananas.') reddit = praw.Reddit(...) # Create a PRAW Reddit instance bot = CommentBot(reddit=reddit, func_comment=parse) bot.start()
-
start
()¶ Starts this bot in a separate thread. Therefore, this call is non-blocking.
It will listen to all new comments created in the
subreddits
list.
-
stop
()¶ Stops this bot.
Returns as soon as all running threads have finished processing.
- reddit –