L
L
lzrdblzzrd2021-08-21 13:39:19
Python
lzrdblzzrd, 2021-08-21 13:39:19

How to get geolocation via Telegram bot using inline?

If you use a bot in Telegram via Inline, then the bot can request the user's location if it is enabled in the bot settings. The geo member in the telethon.events.inlinequery.InlineQuery class is responsible for getting the geolocation .

Here is the code through which I tried to get the geolocation in order to use latitude and longitude in the future:

from telethon import TelegramClient, events

@client.on(events.InlineQuery)
async def handler(event):
    location = event.geo
    builder = event.builder

    await event.answer([
        builder.article("Координаты", text="Долгота: " + location.long + " Широта: " + location.lat),
    ])


But I don't get anything. It keeps giving this:
AttributeError: 'NoneType' object has no attribute 'lat'.

If you type print(location) after getting the location, it will simply print None.
The question is how to get a geolocation that is NOT None?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alan Gibizov, 2021-08-22
@lzrdblzzrd

Hmm ... Apparently, this is your question. There is an answer there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question