1

I'm creating a Telegram Bot and I need to get file_id.for example, photos.

For example:

"AgACAgIAAx0CW7VwqQAD3GE80mUSC6AbGV2lcHFzI5J3me7zAAJwtTEbkWJISbKzPMDueHfrAQADAgADeAADIAQ"

Is there such a possibility and how can I do it?

If you need more information, ask. Thank you!

Lans
  • 21
  • 2
  • you can get `file_id` in `events` or `get_messages` method – Hamidreza Khorammfar Sep 11 '21 at 16:12
  • Right, I can download the file, but is it possible to get file_id, in the format as I described in the question? It's just that I personally would be more comfortable getting the file this way than downloading it. – Lans Sep 11 '21 at 16:17
  • You want to use the `file_id` to access the file whenever you want ? If yes. I think it is better to forward the file somewhere and use the file from there. Because the `file_id` will expire. – Hamidreza Khorammfar Sep 11 '21 at 16:22
  • No, I need file_id for a short time. – Lans Sep 11 '21 at 16:24
  • I found how to get such a file_id from the document, but when you try to get it from the photo gives an error: `'PhotoSize' object has no attribute 'location'`. I tried to call it this way: ```event.file.id``` – Lans Sep 12 '21 at 06:10
  • The method ```await client.pack_bot_file_id(event.photo)``` the same error. – Lans Sep 12 '21 at 06:16

1 Answers1

0

Telethon documentation shows what attributes Document and Photo have.

So you can use the following code:

@client.on(events.NewMessage())
async def downloader(event):
        file = event.document or event.photo
        file_id = file.id