FBChat和python不能发送简单的消息

2024-03-29 06:23:57 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着用fbchat给自己发个信息,每次都会出错。你知道吗

Traceback (most recent call last):

  File "main.py", line 12, in

    client.send(Message(text=msg, thread_id="christopher.batey", thread_type=ThreadType.USER))

TypeError: init() got an unexpected keyword argument 'thread_id'

我要把头发拔出来。我从fbchat文档获取ThreadType,无法绕过此错误。你知道吗

我的代码如下所示:

from fbchat import Client

from fbchat.models import *

client = Client(my_user, my_pass)

name = "christopher.batey"

friends = client.searchForUsers(name)

friend = friends[0]

uid = friend.uid

msg = "This is a test"

sent = client.send(msg, thread_id=uid, thread_type=ThreadType.USER)

Tags: fromimportclientsendiduidtypemsg
1条回答
网友
1楼 · 发布于 2024-03-29 06:23:57

根据你的错误代码,我假设你的代码是这样的:

from fbchat import Client
from fbchat.models import *

client = Client(my_user, my_pass)

name = "christopher.batey"

friends = client.searchForUsers(name)
friend = friends[0]
uid = friend.uid

msg = "This is a test"

sent = client.send(Message(text=msg, thread_id="christopher.batey", thread_type=ThreadType.USER))

最后一部分看起来像是将thread_idthread_type参数放在Message类中,而实际上它们是client.send()函数的参数。它应该是这样的:

sent = client.send(Message(text=msg), thread_id="christopher.batey", thread_type=ThreadType.USER)

希望这能回答你的问题!你知道吗

相关问题 更多 >