我正在尝试通过file_id使用 Pyrogram 下载文档,该程序以错误结束:
pyrogram.errors.exceptions.bad_request_400.FileReferenceExpired: [400 FILE_REFERENCE_EXPIRED]: The file id contains an expired file reference, you must obtain a valid one by fetching the message from the origin context (caused by "upload.GetFile")
.
代码:
import aiogram.utils.markdown as md
from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher import FSMContext
from aiogram.dispatcher.filters import Text
from aiogram.types import ParseMode
from aiogram.utils import executor
bot = Bot(token=BotToken)
storage = MemoryStorage()
dp = Dispatcher(bot, storage=storage)
@dp.message_handler(content_types='document')
async def DownalodDocument(message: types.Message):
await DownloadFile(message.document.file_id)
if __name__ == '__main__':
executor.start_polling(dp, skip_updates=False)
from pyrogram import Client
async def DownloadFile(file_id):
async with Client("my_account", api_id, api_hash) as app:
await app.download_media(file_id)