【问题标题】:How to get users's location and Venue in a bot telegram by telepot如何通过 Telepot 在机器人电报中获取用户的位置和地点
【发布时间】:2020-08-01 08:29:15
【问题描述】:

我正在为巴士路线创建一个带有 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)

【问题讨论】:

  • 向我们展示您正在运行的代码,以及响应的打印输出。
  • 我做到了!好吗?

标签: python bots telegram telepot


【解决方案1】:

您没有向我们显示返回的 msg 响应的打印输出。

if 中,第一行是有意义的,它符合 https://telepot.readthedocs.io/en/latest/reference.html#telepot.Bot.sendMessage.

第二行意义不大,它没有传入参数 https://telepot.readthedocs.io/en/latest/reference.html#telepot.Bot.editMessageLiveLocation 说明你需要。 我没有看到msg_identifier

猜你喜欢
  • 2018-07-17
  • 1970-01-01
  • 2018-01-13
  • 2018-10-23
  • 2022-06-10
  • 2017-08-05
  • 1970-01-01
  • 2017-04-10
  • 2017-12-20
相关资源
最近更新 更多