我正在用Python telepot创建一个公交车行程的机器人。我不明白如何管理命令,谁能给我解释一下,如何获得使用我的机器人的用户的位置(街名)?
import json
import time
from pprint import pprint
import telepot
from telepot.loop import MessageLoop
import telepot.namedtuple
bot = telepot.Bot("token")
lista = ["New York","Los Angeles","Miami","Toronto","Berlin","Rome"]
seq = iter(lista)
keyboard = {"keyboard": [[{"text": i} for i in pair] for pair in zip(seq)]}
def handle(msg):
content_type, chat_type, chat_id = telepot.glance(msg)
print(content_type, chat_type, chat_id)
if content_type == "text":
bot.sendMessage(chat_id, msg["text"], reply_markup=keyboard)
bot.editMessageLiveLocation(latitude, longitude) #i've tried here but nothing
MessageLoop(bot, handle).run_as_thread()
while 1:
time.sleep(10)
解决方案:
你没有给我们看打印输出的? msg
回的回应。
内。if
第1行是有道理的,它符合以下几点https:/telepot.readthedocs.ioenlatestreference.html#telepot.Bot.sendMessage。.
第2行意义不大,它并没有传入的参数是https:/telepot.readthedocs.ioenlatestreference.html#telepot.Bot.editMessageLiveLocation。解释了你的需求。 我看不出 msg_identifier
.