#Paginator, custom button and goto_page()

1 messages · Page 1 of 1 (latest)

leaden turret
#

Sup!

I have a code:

class MainPageButtons(discord.ui.View):
        @discord.ui.button(label="", style=discord.ButtonStyle.primary)
        async def first_but(self, button, interaction):
            await interaction.response.send_message("You pressed me!")


@bot.slash_command(
    name="test", 
    description = "test" 
) 
async def open_shop(ctx: discord.ApplicationContext):
    ShopPages = [
        Page(
            embeds = [discord.Embed(
                title="String1",
                description="String2",
                color=discord.Colour.from_rgb(166, 0 , 255)
                )
            ],
                custom_view=MainPageButtons()
        ),
        Page(
            embeds = [discord.Embed(
                title="String2",
                description="String2",
                color=discord.Colour.from_rgb(166, 0 , 255)
                )
            ],
                custom_view=MainPageButtons()
        )
    ]

    paginator = pages.Paginator(pages=ShopPages, custom_view=None)
    await paginator.respond(ctx.interaction, ephemeral=False)```

I want to make action on button to move to the specific page via goto_page(). But can not understand how to handle it in this situation. I understand that i should replace wait interaction.response.send_message but no idea how to use this method correctly
leaden turret
#

i tried to use

await interaction.goto_page(0, interaction=interaction)

But it fails for sure with AttributeError: 'Interaction' object has no attribute 'goto_page'
So i just trying to understand how it exactly should be

#

dont understand what object should be here

stable folio
#

oh wait i see what you mean

stable folio
#

i'd say assign MainPageButtons() to a variable beforehand

#

like view1 = MainPageButtons()

#

then after defining paginator, you could do view1.paginator = paginator

#

and now in the callback you can access it with self.paginator

leaden turret
#

it works, but makes problem with my prev request where i want to add set of custom buttons for every page

#

because i use same view with set of buttons

stable folio
#

like view1 = MainPageButtons(), view2 = ... etc

#

or maybe you could iterate instead

#
for page in ShopPages:
  if page.custom_view:
    page.custom_view.paginator = paginator``` idk something like that
leaden turret
#

sounds not good , i guess i should really think about architecture of pages . Now it looks like much easier to update (rewrite) original message with embed and use buttons for generating new embed

#

I think i will not break a head with this situation. My goal was getting any specific page from any page. I guess the best workaround is to use custom_view for paginator to go any specific page and inside every page to have custom_view for functions i need and button to return to main menu.

#

Anyway thanks for help. I will hold this topic till tomorrow, maybe someone will reply and give another way. Thanks, Nelo