如何在电报电传机中获取位置?

2024-06-16 12:00:01 发布

您现在位置:Python中文网/ 问答频道 /正文

嗨,我希望我的python聊天机器人能够获取用户的位置。 我找不到代码,你能帮我吗

def testbot_basic():
def handle(msg):
  content_type, chat_type, chat_id = telepot.glance(msg)
  if content_type == 'text':
      bot.sendMessage(chat_id,"ciao sono un Bot")
      print(bot.getMe())
      pprint(bot.getUpdates())

bot = telepot.Bot('xxxxxxxxxxxxx')
print(bot.getMe())
pprint(bot.getUpdates())
#per ogni messaggio ricevuto viene aperta una istanza della funzione handle
bot.message_loop(handle)
print ('Listening ...')
# diamo 10 secondi di pausa
while 1:
    time.sleep(5)

Tags: iddeftypebotchat机器人msgcontent
1条回答
网友
1楼 · 发布于 2024-06-16 12:00:01

明白了

      if content_type == 'location':
      print(msg['location'])
      print(msg['location']['latitude'])
      print(msg['location']['longitude'])

相关问题 更多 >