我尝试使用telepot用python构建我的第一个电报机器人。 我想按命令路由会话,所以我已阅读Telepot Helper Router中的文档,但我不知道如何使用它。
到目前为止,我有:
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)
这给了我这个错误:
AttributeError:'module'对象没有属性'router'
就行:
r = telepot.helper.router(by_chat_command(), {'site': on_site , 'tick':on_tick , 'start':on_start })
我做错了什么?
答案 0 :(得分:0)
问题是你试图调用函数而不是Class。
如果您查看Telepot的来源here,您会看到Router
是一个类
所以而不是:
r = telepot.helper.router
使用
r = telepot.helper.Router