[英]Telegram download media from chat bot in python
机器人向我转发了一些媒体文件,但我无法从机器人聊天中下载媒体。 没有错误,也没有日志警告/消息。它只会崩溃。 我通常毫无困难地使用 download_media() ,但这是我第一次尝试从机器人聊天中下载,请提供任何建议,
没有错误
#!/usr/bin/env python3.9
import asyncio
from telethon import TelegramClient
from telethon import errors
import logging
logging.basicConfig(level=logging.DEBUG)
logging.getLogger('telethon').setLevel(level=logging.DEBUG)
async def login(client, phone):
print("Start...")
await client.connect()
if not await client.is_user_authorized():
print("Requesting auth..")
await client.send_code_request(phone)
await client.sign_in(phone, int(input('Enter code: ')))
try:
async with client.takeout(finalize=False) as takeout:
print("Connected...")
return takeout
except errors.TakeoutInitDelayError:
print("Please confirm and restart (+42777)")
return False
异步定义开始():
api_id =
api_hash =
tel =
client = TelegramClient('test', api_id, api_hash)
takeout = await login(client, tel)
if not takeout:
loop.stop()
channel = await takeout.get_input_entity('https://t.me/xxxxx_Bot')
msgs = await takeout.get_messages(channel) # get message object
print(msgs) # print message OK
await client.download_media(msgs) # has no effect , no error or log strings
loop.stop()
loop = asyncio.get_event_loop()
try:
task_start = loop.create_task(start())
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
pass
如何从机器人聊天中下载媒体? 感谢
代码没有错误。 我在操作系统上犯了一个错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.