FBChat和python无法发送简单消息

时间:2019-08-26 18:12:20

标签: python python-3.x

因此,我尝试通过fbchat向自己发送消息,并且每次我得到错误消息。

  

回溯(最近通话最近一次):

     

中的文件“ main.py”,第12行      

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

     

TypeError: init ()获得了意外的关键字参数'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)

1 个答案:

答案 0 :(得分:0)

根据您的错误代码,我假设您的代码实际上是这样的:

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自变量实际上是client.send()函数的自变量放在Message类中。它应该看起来像这样:

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

希望能回答您的问题!