在 python 中从聊天机器人下载媒体文件
Telegram download media from chat bot in python
一个机器人转发给我一些媒体文件,但我无法从机器人聊天中下载媒体。没有错误,也没有日志 warning/message。它只是崩溃了。我通常使用 download_media() 没有困难,但这是我第一次尝试从 bot chat 下载,请任何建议,
没有错误
#!/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
async def start():
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
如何从机器人聊天下载媒体文件?
谢谢
代码没有错误。
msgs = await takeout.get_messages(channel)
get_messages() 仅获取已读消息....
一个机器人转发给我一些媒体文件,但我无法从机器人聊天中下载媒体。没有错误,也没有日志 warning/message。它只是崩溃了。我通常使用 download_media() 没有困难,但这是我第一次尝试从 bot chat 下载,请任何建议,
没有错误
#!/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
async def start():
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
如何从机器人聊天下载媒体文件? 谢谢
代码没有错误。
msgs = await takeout.get_messages(channel)
get_messages() 仅获取已读消息....