Reddit bot错误:“出现错误:'unicode'对象不可调用”

时间:2018-11-17 23:38:04

标签: python-3.x praw

我目前正在尝试设置一个机器人,该机器人监视subreddit上的关键字,然后通过PM向我发送警报。

我真的是Python新手。我的第一个问题是在哪里可以找到错误日志?

我使用的是我发现的here代码。

import praw
from time import sleep

#  http://praw.readthedocs.io/en/latest/getting_started/authentication.html
reddit = praw.Reddit(client_id='your app client id',
             client_secret='your app client secret',
             username='your bot reddit username',
             password='your bot reddit password',
             user_agent='python3:KeyWordNotify:v1 (/u/Arkaon)')


you = reddit.redditor('your reddit username')  # this is the account that will receive the messages
subreddit = reddit.subreddit('your subreddit name')  # scan comments in this subreddit

keywords = ['keyword1', 'keyword2', 'keyword3']  # case insensitive
ignore_users = ['baduser1', 'baduser2', 'baduser3']  # case SENSITIVE

already_alerted_submissions = []  # a list of submission ids that you have already been notified for

comment_stream = subreddit.stream.comments()


def main():
    try:
        for comment in comment_stream:

            if comment.submission.id in already_alerted_submissions: continue

            if comment.author:  # if comment author hasn't deleted
                if comment.author.name in ignore_users: continue

            for kw in keywords:
                if kw.lower() in comment.body.lower():  # case insensitive check

                    msg = '[Keyword {0} detected](http://www.reddit.com{1})'.format(kw, comment.permalink())
                    you.message(subject='keyword detected', message=msg)  # send the PM
                    print(msg)

                    already_alerted_submissions.append(comment.submission.id)

    except Exception as e:
        print('There was an error: ' + str(e))
        sleep(60)  # wait for 60 seconds before restarting
        main()


if __name__ == '__main__':
    main()

我相信我在Windows 10上运行Python 3.7.0,并相信使用PRAW 10.0。

我已经安装并运行了机器人程序,它可以检测到何时关键字已发布到特定的subreddit上,但是当它检测到关键字时,它将在终端上发布以下内容

There was an error: 'unicode' object is not callable

并且不发送PM。

当我关闭bot时,得到以下输出

There was an error: 'unicode' object is not callable

^CTraceback (most recent call last):

File "keyworkdbot.py", line 48, in <module>

main()

File "keyworkdbot.py", line 44, in main

main()

File "keyworkdbot.py", line 43, in main

sleep(60) # wait for 60 seconds before restarting

KeyboardInterrupt

有人知道我该如何解决这个问题?

提前谢谢

0 个答案:

没有答案