如何在class EchoBot
之外打印讯息?
问题是,每当我尝试在课外打印消息时,它都不会显示或仅显示错误消息未定义。
import fbchat
class EchoBot(fbchat.Client):
def __init__(self,email, password, debug=True, user_agent=None):
fbchat.Client.__init__(self,email, password, debug, user_agent)
def on_message(self, mid, author_id, author_name, message, metadata):
self.markAsDelivered(author_id, mid) #mark delivered
self.markAsRead(author_id)#mark read
print("%s said: %s"%(author_id, message))
if str(author_id) != str(self.uid):
self.send(author_id,message)
bot = EchoBot("ID", "PASSWORD")
bot.listen()