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: '_io.BytesIO' object has no attribute 'name' in paginator #1869

Merged
merged 10 commits into from
Jan 11, 2023
Merged

fix: '_io.BytesIO' object has no attribute 'name' in paginator #1869

merged 10 commits into from
Jan 11, 2023

Conversation

yoggys
Copy link
Contributor

@yoggys yoggys commented Jan 11, 2023

Summary

Fix issue with discord/ext/pages/pagination.py update function while using e.g. io.BytesIO.
Files that cannot be updated are skipped.

Discord forum post

Information

  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed).
  • This PR is not a code change (e.g. documentation, README, typehinting,
    examples, ...).

Checklist

  • I have searched the open pull requests for duplicates.
  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • If type: ignore comments were used, a comment is also left explaining why.

@yoggys yoggys requested a review from a team as a code owner January 11, 2023 11:17
@CompuGenius-Programs
Copy link
Contributor

@yoggys, Thanks for this!

@Nzii3
Copy link
Contributor

Nzii3 commented Jan 11, 2023

@yoggys Has the updated code been tested to make sure this works? If so, please provide screenshots and code usages so I can test this out myself with my test build.

@Nzii3
Copy link
Contributor

Nzii3 commented Jan 11, 2023

Me and Bob are talking about the update_files() function, and it doesn’t seem to really update the files, since they are updated each time the page is changed.

@CompuGenius-Programs
Copy link
Contributor

@yoggys Has the updated code been tested to make sure this works? If so, please provide screenshots and code usages so I can test this out myself with my test build.

Here's a screenshot of the embed successfully having the proper image, which was sent with io.BytesIO. Without the above fix, the bot throws the error when trying to click to another page.

Screenshot_20230111_170431

Here's my code:

with open(file_name, 'rb') as fp:
    data = io.BytesIO(fp.read())
file = discord.File(data, file_name)

@yoggys
Copy link
Contributor Author

yoggys commented Jan 11, 2023

@yoggys Has the updated code been tested to make sure this works? If so, please provide screenshots and code usages so I can test this out myself with my test build.

image

import logging
import sys
from io import StringIO

import discord
from discord.ext import commands, pages

logging.basicConfig(stream=sys.stdout, level=logging.INFO)

class Bot(commands.Bot):
    def __init__(self):
        super().__init__(command_prefix = '.', intents=discord.Intents.all())

bot = Bot()

@bot.slash_command()
async def teststringio(
    ctx: discord.ApplicationContext, 
): 
    test = discord.Embed(title="test", description="test")
    
    p = []
    for i in range(5):
        p.append(pages.Page(embeds=[test], files=[discord.File(StringIO(f"{i}"), f"test{i}.txt")]))
    paginator = pages.Paginator(pages=p, disable_on_timeout=True)
    await paginator.respond(ctx.interaction)
    
@bot.slash_command()
async def testreadingbuffer(
    ctx: discord.ApplicationContext, 
): 
    test = discord.Embed(title="test", description="test")
    
    p = []
    for i in range(5):
        p.append(pages.Page(embeds=[test], files=[discord.File(f"test{i}.txt")]))
    paginator = pages.Paginator(pages=p, disable_on_timeout=True)
    await paginator.respond(ctx.interaction)
            
bot.run("token")

Copy link
Member

@BobDotCom BobDotCom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the suggestion I added. Also, please add a changelog entry.

discord/ext/pages/pagination.py Outdated Show resolved Hide resolved
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Signed-off-by: Mateusz <61660055+yoggys@users.noreply.github.com>
yoggys and others added 3 commits January 11, 2023 16:27
Co-authored-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
Signed-off-by: Mateusz <61660055+yoggys@users.noreply.github.com>
@yoggys
Copy link
Contributor Author

yoggys commented Jan 11, 2023

whops, wrong section - i moved it to Changed

BobDotCom and others added 2 commits January 11, 2023 10:32
Fixes compatibility with older python versions
CHANGELOG.md Outdated Show resolved Hide resolved
BobDotCom and others added 2 commits January 11, 2023 10:44
Signed-off-by: BobDotCom <71356958+BobDotCom@users.noreply.github.com>
@BobDotCom BobDotCom enabled auto-merge (squash) January 11, 2023 16:46
@BobDotCom BobDotCom requested a review from a team January 11, 2023 17:15
@Lulalaby Lulalaby disabled auto-merge January 11, 2023 19:52
@BobDotCom BobDotCom enabled auto-merge (squash) January 11, 2023 22:17
Copy link
Member

@Lulalaby Lulalaby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well then, lgtm

here we go~

@BobDotCom BobDotCom merged commit 767635f into Pycord-Development:master Jan 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants