Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

@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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading