From 2ddab49b40c23d00893dda9aab7b90aa9ac6b2b1 Mon Sep 17 00:00:00 2001 From: BobDotCom <71356958+BobDotCom@users.noreply.github.com> Date: Tue, 17 Jan 2023 13:27:36 -0600 Subject: [PATCH] apply new fix --- discord/ext/pages/pagination.py | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/discord/ext/pages/pagination.py b/discord/ext/pages/pagination.py index 9d44a44a95..6bffc7e194 100644 --- a/discord/ext/pages/pagination.py +++ b/discord/ext/pages/pagination.py @@ -23,7 +23,6 @@ """ from __future__ import annotations -from io import BufferedReader from typing import List import discord @@ -169,26 +168,14 @@ async def callback(self, interaction: discord.Interaction | None = None): """ def update_files(self) -> list[discord.File] | None: - """Re-opens and reads new file contents for local files if they were updated. - Typically used when the page is changed. + """Updates :class:`discord.File` objects so that they can be sent multiple + times. This is called internally each time the page is sent. """ for file in self._files: - if not isinstance(file.fp, BufferedReader): - file.fp.seek(0) - self._files[self._files.index(file)] = discord.File( - file.fp, # type: ignore - filename=file.filename, - description=file.description, - spoiler=file.spoiler, - ) - else: - with open(file.fp.name, "rb") as fp: # type: ignore - self._files[self._files.index(file)] = discord.File( - fp, # type: ignore - filename=file.filename, - description=file.description, - spoiler=file.spoiler, - ) + if file.fp.closed and (fn := getattr(file.fp, "name", None)): + file.fp = open(fn, "rb") + file.reset() + file.fp.close = lambda: None return self._files @property