如何向此 reddit 机器人代码添加更多 subreddits/keywords?
How do I add more subreddits/keywords to this reddit bot code?
我在 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 的了解有限。我希望机器人扫描多个 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():
我在 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 的了解有限。我希望机器人扫描多个 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():