Button interaction question about discord. Py

60 Views Asked by At

How do i use bot.wait_for for button_clicked and how do i get interaction id?

And if view is running in two guilds at same time will it be different or same? Because i want to run some function on it so it might get called for another guild

1

There are 1 best solutions below

0
Raymus On

button_clicked event for bot.wait_for was only for discord-components, which is outdated and should not be used.

The best solution is to use the button.callback function.

class MyView(discord.ui.View):
    def __init__(self):
        super().__init__()
    
    @discord.ui.button(label=“Click me!”)
    async def mybutton_callback(self, interaction: discord.Interaction, button: discord.ui.Button):
        await interaction.response.send_message(content=“Hello world”)

The wait_for function waits for an event to happen, in this case, button_clicked does not exist within Discord.py and was in discord-components.

This code gives a basic representation of how a button works in Discord.py.

For more information, discord.ui.View, discord.ui.Button.