Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: images sending as 0 bytes in paginator if sent as io.BytesIO #1881

Merged
merged 11 commits into from
Jan 18, 2023
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ These changes are available on the `master` branch, but have not yet been releas

### Fixed

- Fixed a bug in `Page.update_files` where `io.BytesIO` files didn't send properly more
than once.
Lulalaby marked this conversation as resolved.
Show resolved Hide resolved
CompuGenius-Programs marked this conversation as resolved.
Show resolved Hide resolved

- Fixed a bug in `Page.update_files` where file objects stored in memory were causing an
`AttributeError`. ([#1869](https://github.com/Pycord-Development/pycord/pull/1869))

Expand Down
13 changes: 10 additions & 3 deletions discord/ext/pages/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,21 @@ def update_files(self) -> list[discord.File] | None:
"""
for file in self._files:
if not isinstance(file.fp, BufferedReader):
CompuGenius-Programs marked this conversation as resolved.
Show resolved Hide resolved
continue
with open(file.fp.name, "rb") as fp: # type: ignore
file.fp.seek(0)
self._files[self._files.index(file)] = discord.File(
fp, # type: ignore
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,
)
return self._files

@property
Expand Down