#paginator

1 messages · Page 1 of 1 (latest)

ornate brook
#

Is it possible in the built-in paginator to make buttons instead of page embeds, that is, so that when you turn the page, the buttons change. In my example, the button is a product

hardy veldt
#

You can use a custom view/custom button so yeah I think

#

Well you might have to edit each time the paginator button to put ur view so maybe a dropdown will be better with the emoji as product, Name and description

ornate brook
#

Thank you, i roughly understood

hardy veldt
#

Sorry my English is not the best but if u need more explanation ask me I will try my best

ornate brook
#
class SelectSpecial(discord.ui.Button):
  def __init__(self, bot, label):
    super().__init__(
      label=label,
      emoji="📢",
      custom_id="offers_select",
      style=discord.ButtonStyle.red
    )
    self.bot = bot
  async def callback(self, interaction: discord.Interaction):
    pool = await aiomysql.create_pool(host=config["host"], port=config["port"], user=config["user"], password=config['password'], db=config["db"])
    async with pool.acquire() as conn:
      async with conn.cursor() as cursor:
        await cursor.execute("SELECT lang FROM users WHERE user_id = %s",(interaction.user.id,))
        result = await cursor.fetchone()
        lang = result[0]
        await cursor.execute("SELECT * FROM special_offers")
        result = await cursor.fetchall()
        view = discord.ui.View(timeout=None)
        view.add_item(BackToAdmin(self.bot, label="Назад" if lang == 'ru' else 'Back'))
        view.add_item(CreateSpecialOffers(self.bot, label="Создать товар" if lang == 'ru' else 'Create product'))
#
        options = []
        
        pages_list = []
        page_size = 2
        if len(result) > page_size:
          for i, row in enumerate(result):
            id = row[0]
            name = row[1] if lang == 'ru' else row[2]
            emoji = row[4]
            description = row[5] if lang == 'ru' else row[6]
            status = row[11]
            if len(description) > 98:
              description = description[:98] + "…"
            options.append(discord.SelectOption(label=name, emoji=emoji, description=description, value=str(id)))
                    
            if (i + 1) % page_size == 0 or i + 1 == len(result):
              pages_list.append(options)
              options = []

          paginator = pages.Paginator(pages=pages_list, use_default_buttons=False, loop_pages=True)
          paginator.add_button(pages.PaginatorButton('prev', emoji="⬅️", style=discord.ButtonStyle.red))
          paginator.add_button(pages.PaginatorButton('next', emoji="➡️", style=discord.ButtonStyle.green))
          paginator.add_button(pages.PaginatorButton('page_indicator', style=discord.ButtonStyle.gray, disabled=True))
ornate brook
#

Current error: all items must be embeds or files.

hardy veldt
#

What I was meaning is use a select menu, when the user select the time you edit the embed with the other product. And so not use paginator but select menu

ornate brook
hardy veldt
#

like not using paginator but a dropdown