I use disnake library for my discord bot and it has such thing as listeners. Which are, basically, handling the on_button_click and other events. I use different listeners via @commands.Cog.listener() in separate files, both are on_button_click type. I made sure event handlers are assigned properly inside of their classes. However, when the button is pressed I still get an error from both commands even tho only one was executed. I think the cause of the problem may be importing EconomyLogic class in the both cogs.
#๐ Event handling overlap
10 messages ยท Page 1 of 1 (latest)
@rose shoal
Remember to:
- Ask your Python question, not if you can ask or if there's an expert who can help.
- Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
- Explain what you expect to happen and what actually happens.
:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.
Closes after a period of inactivity, or when you send !close.
When you press the button both events are executed and may cause conflicts. Consider using a single event or handling that in the button callback
Would it be better if I create a separate file for the event handler with all possible actions?
Yes, you could do it that way. Create a cog that handles the events just make sure they are unique events
Thank you, also in that case would I need to rather import the variables or make an __init__ with all the variables like user, avatarUrl, etc?
I don't know how disnake handles interactions because I use another library but in the documentation it says that the on_button_click() event receives a MessageInteraction object. You can access all the information you need from that object
This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.