在 reddit python 机器人回复中增加数字

increment number in reddit python bot reply

我正在尝试制作一个机器人,每次有人提到一个字符串时它都会递增一个数字。到目前为止,我只能让它递增一次,而其他所有回复都保持相同的数字。它在 2017 年声明,但只有在找到字符串时才会回复 2018。我知道我遗漏了一些小东西,但我想不通。

for comment in r.subreddit('test').comments(limit = 500):
        mentions = 2017     
        if "string" in comment.body and comment.id not in comments_replied_to and comment.author != r.user.me():
            mentions +=1
            print ("string found!") and comment.id
            comment.reply(" delayed until year" + str(mentions))
            print("replied to comment")

您在mentions内部循环体中声明,这意味着它将在每次迭代时设置为2017

此外,print ("string found!") and comment.id 应该是 print("string found!", comment.id)

在循环内部而不是外部声明提及,这解决了问题