编写Reddit自动机器人代码,而不是注释列表的所有部分



所以我正在为我在python中审核的subreddit编写一个机器人。机器人能够执行,并且能够正确回复评论,但它只回复列表的最后一部分。(评论是针对使用该子的其他人的)。代码还没有完成,到目前为止我只在一个区域完成了它,但除了那一部分之外,一切似乎都可以工作。请你告诉我我应该怎么做。

例:

评论: U/crazy_angel1: Automaester Raven North回复: u/AutoMaesterGOT: u/CptAwsome12345

法典:

import time
#importing time module
import praw
#importing the thing that allows you to run all the code, if you want to run this on your own computer, you will need to install it, look for a tutorial on how to install PRAW online
reddit = praw.Reddit(client_id='redacted',
username='AutoMaesterGOT',
client_secret='redacted',
password='redacted',
user_agent='It is a script that messages people every time a certain phrase is passed in my subreddit. Created by /u/crazy_angel1')
print("logging in...")
print(reddit.user.me())
#singing on to the bot with OAuth, again look up online if you want to use it
WordCalls=['AUTOMAESTER RAVEN NORTH', 'AUTOMAESTER RAVEN CROWNLANDS', 'AUTOMAESTER RAVEN CROWNLANDS','AUTOMAESTER RAVEN WESTERLANDS', 'AUTOMAESTER RAVEN DORNE','AUTOMAESTER RAVEN VALE','AUTOMAESTER REACH', 'AUTOMAESTER RAVEN IRON ISLANDS']
#the terms that will call the bot
CommentCache=[]
#storing comments already sorted through
NorthMembers=['u/crazy_angel1','u/StraightOuttaNYC','u/jgames2000','u/CptAwsome12345']
def BOTRUN(): #the bots main code for North
subreddit = reddit.subreddit('StormOfSwordsRP')#connecting to the subreddit
comments = subreddit.stream.comments()#sorting through comments
for comment in comments:
comment_body = comment.body#storing each individual comment
comment_body = comment_body.upper()#making every comment uppercase
isMatch = any(string in comment_body for string in WordCalls)#setting conditions for calling bot 
if isMatch and comment.id not in CommentCache:#checking if anybody has called bot and it hasnt already been replied to yet
print("match found, comment id" +comment.id)
comment.reply(NorthMembers)#calling North members
CommentCache.append(comment.id)#adding the comment id to the cache
print("reply succesful")
while True: #infinite loop
BOTRUN()# executing bot
time.sleep(10)

所以显然reddit不喜欢列表,所以如果你尝试正常回复列表,它将无法正常工作。所以代替线

评论回复(北方成员)

您将需要使用以下行:

Comment.reply(' '.join (NorthMembers))

感谢@xay的帮助

最新更新