【发布时间】:2020-09-26 10:38:28
【问题描述】:
我正在尝试制作一个机器人,以便当有人向它发送消息时,机器人会发回一个笑话,但我注意到这仅适用于我的朋友列表中的人,但如果随机人发送给机器人,那么他们的消息卡在 messenger 上的消息请求中,甚至 fbchat 库都识别到了这一点,并在控制台中告诉我有一条新的待处理消息,那么有没有办法回应这些消息?
这是我的代码:
from fbchat import Client,ThreadLocation
class JokesBot(Client):
def onMessage(self, author_id, message_object, thread_id, thread_type, **kwargs):
self.moveThread(ThreadLocation.PENDING,thread_id,thread_type)
self.markAsDelivered(thread_id, message_object.uid)
self.markAsRead(thread_id)
# If you're not the author, echo
if author_id != self.uid:
self.send(Message(text='wiso tefl hehe'), thread_id=thread_id, thread_type=thread_type)
client = JokesBot('email', 'password')
client.listen()
请记住,我仍然没有实现这些笑话,所以代码中缺少它
提前致谢
【问题讨论】:
标签: python python-3.x bots facebook-messenger facebook-messenger-bot