【发布时间】:2021-05-11 23:41:34
【问题描述】:
我正在研究用于从电报下载媒体的 Telethon download_media 和 _download_document 方法。我的代码是这样的:
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())
但此代码无法将媒体下载到特定路径, 以及如何获取已保存文件的名称
【问题讨论】:
标签: python file telegram telegram-bot telethon