Skip to content
This repository has been archived by the owner on Aug 29, 2021. It is now read-only.

Can U Set an Example How to paginate data that exceed discord character limit in embed ? #23

Closed
clearmyskin opened this issue Oct 6, 2020 · 1 comment

Comments

@clearmyskin
Copy link

AccountInfo` = f"**Total Accounts:**{TotalAccounts}\n{AccountList}\n**All Account Summary:**\n **Total Money:** ${yess}\n **Withdrawn:** ${outmoney}\n **Unclaimed:** ${noo}" try: if len(AccountInfo) > 2048: embed=discord.Embed(title=None,description=AccountInfo[:1905],color=0x9999ff) embed.set_author(name=f"{ctx.author.name}'s Profile", icon_url=ctx.author.avatar_url) embed2=discord.Embed(title=None,description=AccountInfo[1905:],color=0x9999ff) embed2.set_author(name=f"{ctx.author.name}'s Profile", icon_url=ctx.author.avatar_url

I want to Paginate Even if it exceed my character limit i am using now is 3000 but when character exceed bot dont send message
:(

@robertwayne
Copy link
Owner

robertwayne commented Oct 6, 2020

The library currently won't automatically paginate (I guess the menu name can be a bit misleading), so you have to manually define pages. There is an auto PaginatedMenu in the works, however.

My recommendation would be to pre-build your pages in a loop. You could use a generator if you are concerned about memory, but I can't see that being a big issue unless you're making hundreds of thousands of pages.

Choose how many items you want displayed per page, then do something like this:

# this will let us build a list of sized chunks that we can then use to build our pages
def split_data(data, chunk_size):
    for i in range(0, len(data), chunk_size):
        yield data[i : i + chunk_size]

# we'll pass in our account list and break it into 10 accounts per page
account_info = list(split_data(account_list, 10))

# now we have a list of lists, so we can iterate over that to build our pages
# you can turn use list comprehension for more performance here as well, but for readability sake we'll do it the naive way
pages = []
for item in account_info:
    pages.append(Page(title='Title', description=item))

After that, just pass the list of pages into the .add_pages method and you're good to go.

This isn't tested code, but it should give you an idea on how to go about dynamically chunking your data and then turning it into a bunch of pages.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants