'Call a python function on button click in discord_components (python)
I am making a bot in discord.py, and I want to call a function inside the code whenever someone presses a button. I looked at the documentation of discord_components(lib for buttons and select menus), but it's either I'm stupid or the documentation is bad. I also googled it but didn't find anything.
So is it possible to run a function on the interaction event?
Solution 1:[1]
@bot.event
async def on_button_click(interaction):
your_func()
You can just go with the flow. Be careful not to forget to send a callback. Here is the link to the event examples on the discord components github: examples.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | mdevolde |
