我在 GitHub 上找到了这个 reddit 机器人代码,它实际上只是一个评论机器人。
https://github.com/yashar1/reddit-comment-bot
我对 Python 知之甚少,因此我尝试修改代码以使其具有多个 subreddits 和关键字,并添加以下内容:
keywords = ["hello", "okay"]
subreddits = ["test", "bottest"]
for comment in r.subreddit(any(subreddits)).comments(limit=100):
if any(keywords) in comment.body and comment.id not in comments_replied_to
and comment.author != r.user.me():
这段代码似乎不起作用,主要是由于我对 Python 的了解有限。我希望机器人扫描多个 subreddit 并搜索多个关键字。
谢谢。
您可以像这样包含多个 subreddits。
subreddits_list = "test+bottest"
subreddits = r.subreddit(subreddits_list)
要检查多个关键字,您可以使用。
keywords = ["hello", "okay"]
for comment in subreddits.comments(limit=100):
for keyword in keywords:
if keyword in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句