#Paginator help

1 messages · Page 1 of 1 (latest)

wanton thorn
#

@drowsy nest You were really helpful a few months ago with helping set up a persistent paginator. Now I'm trying to add pages based on player input from my db, as you suggested here: #998272089343668364 message

The crux of my question now is that since I'm creating pages in a function with lots of if/else logic, I'm unsure as to how to add the pages to the bot and on_ready.

Here's the general idea:

The slash command to create the user's paginator from their db values


@bot.slash_command(name="postPaginator")
  [read db values, push to 'result']
   if ...:
       paginator = pages.Paginator(pages=[
           pages.Page(result[0][2] + "text",
                      files=[firstPageImage]),
           pages.Page(result[0][3]+ "text", files=[secondPageImage])],
           loop_pages=False, use_default_buttons=False
       )
   if ...::
       paginator = pages.Paginator(pages=[
           pages.Page(result[0][5] + "text",
                      files=[firstPageImage]),
           pages.Page(result[0][6] + "text", files=[secondPageImage]),
           pages.Page(result[0][7] + "text", files=[thirdPageImage])],
           loop_pages=False, use_default_buttons=False
       )


   paginator.add_button(
       CustomButtons("prev", label="<", custom_id="paginator1 + [uniqueid from db]", style=discord.ButtonStyle.green))
   paginator.add_button(
       CustomButtons("page_indicator", custom_id="paginator + [uniqueid from db]", style=discord.ButtonStyle.gray, disabled=True))
   paginator.add_button(
       CustomButtons("next", label=">", custom_id="paginator + [uniqueid from db]", style=discord.ButtonStyle.green))
   paginator.timeout = None
#custom ids need to include uniqueid from db.
   await paginator.respond(ctx.interaction)
#

Adding to on_ready

How we got this working before was with something like:

   async def on_ready(self):
        paginator = Paginator(pages=[pages.Page("'s Character Sheet", files=[drawnImage]),
                                      pages.Page("'s Character Sheet", files=[drawnImage]),
                                      "Page 3"], use_default_buttons=False, custom_buttons=customButtons2(),
                               author_check=False)
        paginator.timeout = None
        paginator.update_buttons()
        bot.add_view(paginator)
        paginator2 = Paginator(pages=[pages.Page("'s Character Sheet", files=[drawnImage]),
                                      use_default_buttons=False, custom_buttons=customButtons3(),
                               author_check=False)
        paginator2.timeout = None
        paginator2.update_buttons()
        bot.add_view(paginator2)

Where each paginator being posted needed to be exactly duplicated in on_ready. But of course now I can't specify exactly what's in each paginator because they're being made from the function based on the db values.

#

I guess my question boils down to is how should I push each paginator made from the slash command to on_ready. bot.add_view(paginator) in the slash command didn't seem to work.

#

I saw you recently worked on ext.pages... maybe something in there could help?

#

Any insight will be much appreciated!!

wanton thorn
#

I figured this out by looping through all rows in the db in on_ready, making a paginator with each added to on_ready, and adding a custom id to each button based on the row id. 🙂