如果您通过 Telegram 中的内联使用机器人,机器人可以请求用户的位置,如果在机器人设置中启用了此功能。telethon.events.inlinequery.InlineQuery类负责获取地理位置。
这是我试图获取地理位置以便将来使用纬度和经度的伪代码:
from telethon import TelegramClient, events
@client.on(events.InlineQuery)
async def handler(event):
location = event.geo
builder = event.builder
await event.answer([
builder.article("Coordinates: ", text="Long: " + location.long + "\nLat: " + location.lat),
])
但我什么也做不了。不断输出AttributeError: 'NoneType' object has no attribute 'lat'
。
如果您能帮助我获取和使用这些数据,我将不胜感激。