Reddit 机器人在检查所有评论后停止

Reddit bot stops after checking all comments

我编写了一个 reddit 机器人程序并对其进行了大量测试,我可以说它运行良好,除了最后一部分自动化。它第一次检查留在那里的每条评论,并从称为数组的列表中回复它们 truthsdares 当它完成时它只打印它检查的消息但不对新评论做任何事情。我正在使用 PRAW(Pythons Reddit API Wrapper) 和 python 3.5。谢谢

    #1. Import libraries
import praw
import random
import time

#2. Write the truths and dares
dares = ["Draw snoo", "Draw the android logo", "Spin in a circle for a minute", "Wish a random contact on a social media platform Happy birthday but it isn't their birthday", "Eat a potato" ]
truths = ["Do you like someone on this subreddit", "Do you do drugs","Do you watch porn", "Do you pirate stuff", "What is your favorite Disney princess", "How many times have you been drunk"]
cache = []


#3. Connect to reddit
r = praw.Reddit(user_agent = "TruthAndDare by @UnknownDevelope /u/unknowndeveloper")
r.login("Username","pass")

def run_bot():
    print("Getting Subreddit ...")
    subreddit = r.get_subreddit("subreddit")
    print("Getting comments ...")
    comments = subreddit.get_comments(limit=200)
#4. Check subreddit
#5. Check for a truth or a dares
#6. Reply

submission = r.get_submission(submission_id='submissionid')
flat_comments = praw.helpers.flatten_tree(submission.comments)
already_done = set()
for comment in flat_comments:
    if comment.body == "/u/TruthAndDareBot Truth" and comment.id not in already_done:
        randomTruth = random.choice(truths)
        comment.reply(randomTruth)
        print("SIR I found a truth and im gonna reply to it. The post ID is: "+ comment.id)
        cache.append(comment.id)
    if comment.body == "/u/TruthAndDareBot Dare" and comment.id not in already_done:
        randomDare = random.choice(dares)
        comment.reply(randomDare)
        print("SIR I found a Dare and im gonna reply to it. The post ID is: "+ comment.id)
        cache.append(comment.id)


while True:
    run_bot()
    time.sleep(10)

这部分代码未正确缩进,因此无法运行。这是它应该如何工作的代码:

def run_bot():
        print("Getting Subreddit ...")
        subreddit = r.get_subreddit(SUBREDDIT)
        print("Getting comments ...")
        comments = subreddit.get_comments(limit=SUBMISSION_ID)
        submission = r.get_submission(submission_id='49q8l1')
        flat_comments = praw.helpers.flatten_tree(submission.comments)
        already_done = set()
        for comment in flat_comments:
            print comment.body
            if comment.body == "/u/TruthAndDareBot Truth" and comment.id not in already_done:
                randomTruth = random.choice(truths)
                comment.reply(randomTruth)
                print("Found a truth and I'm going to reply to it. Comment ID is: "+ comment.id)
                cache.append(comment.id)
            if comment.body == "/u/TruthAndDareBot Dare" and comment.id not in already_done:
                randomDare = random.choice(dares)
                comment.reply(randomDare)
                print("Found a Dare and I'm going to reply to it. Comment ID is: "+ comment.id)
                cache.append(comment.id)