I’m working on telethon download_media and _download_document methods for downloading media from telegram. My code is something like this:
from telethon import TelegramClient
api_id = 12345
api_hash = '0123456789abcdef0123456789abcdef'
client = TelegramClient('anon', api_id, api_hash)
async def main():
async for message in client.iter_messages('me'):
print(message.id, message.text)
# You can download media from messages, too!
# The method will return the path where the file was saved.
if message.photo:
path = await message.download_media()
print('File saved to', path) # printed after download is done
with client:
client.loop.run_until_complete(main())
But this code cannot download the media to a specific path,
and How Can I get the name of file that saved
2
Answers
Docs of telethon shows that
download_media
method accepts argument namedfile
, which isI do not have ability to test it, but something like replacing
with
should work.
You Can get File name by Using
message.file.name
, Here is Code