我正在尝试使用telepot来构建我的第一个带有python的电报机器人。我想通过命令路由对话,所以我已经阅读了 Telepot 助手路由器中的文档,但我不知道如何使用它。
到目前为止,我有:
import telepot
from telepot.routing import by_chat_command
def on_site(chat_id,msg):
#function code
def on_tick(chat:id,msg):
#function code
def on_start(chat_id,msg):
#function code
r = telepot.helper.router(by_chat_command(), {'site': on_site , 'tick':on_tick , 'start':on_start })
bot.routing_table['text']=r.route
bot = telepot.Bot('TOKEN')
bot.message_loop()
print ('Listening....')
#LOOP
while 1:
time.sleep(10)
这给了我这个错误:
属性错误:"模块"对象没有属性"路由器"
在线上:
r = telepot.helper.router(by_chat_command(), {'site': on_site , 'tick':on_tick , 'start':on_start })
我做错了什么?
问题是您正在尝试调用函数,而不是 Class。如果您在此处检查Telepot的来源,您将看到Router
是一个类
所以代替:
r = telepot.helper.router
用
r = telepot.helper.Router