#Dynamic Buttons/Select Menus

1 messages · Page 1 of 1 (latest)

steep gull
#

Is it possible to dynamically create a set of buttons? E.g. for v in list: option.add?

#

option.add(v)*

long lynx
#

view.add_item(button)

steep gull
#

So would this work?

view = viewbut()
for v in listobj:
   view.add_item(v)

(With v being implemented into a button object I used just v for simplicity)

steep gull
#

@long lynx

steep gull
# long lynx .tias

It worked! However, how do I check when it's called? The typical arragement is this:

...
class View(discord.ui.View):
    def __init__(self):
        #self.bot = bot
        super().__init__(timeout=None)

    @discord.ui.button(label="test", style=discord.ButtonStyle.green, custom_id="testbut1")
    async def reactbutton(self, button: discord.ui.Button, interaction: discord.Interaction):
        await interaction.response.send_message(button.label)
...
@discord.slash_command(name="button",description="test") # we can also add application commands
    async def button(self, ctx):
        view = View()
        view.add_item(discord.ui.Button(label="test1", style=discord.ButtonStyle.green, custom_id="testbut2"))
        await ctx.respond("Test", view=view)
...

I can't activate the view components without called ui.button and I don't know how to check if the ui itself is called