#Discord Embed Buttons

15 messages · Page 1 of 1 (latest)

steady cloud
#

Hi! So I'm working on a ticket system for my bot and I added tickets to claim and close the ticket. The only problem I'm having right now is that when I have multiple tickets, and I press a button, the button makes all the tickets do the same action. I want only that ticket to do the action. Afterwards, the code creates an error!

Code: https://pastebin.com/vDXs4yN9
Discord.js version: v14.2.0

full archBOT
#

• What's your exact discord.js npm list discord.js and node node -v version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.

steady cloud
#

Image of the ticket:

low lava
#

When the button is pressed, how you are handling it to close/claim? (Edit: ops, I didnt see your pastebin. Sorry)

#

And, are you storing the tickets somewhere besides the message itself, like a database?

#

The button press will fire the same event for every button. So, you need to decide how to identify the specific ticket to claim/close, like using the message id or database id of it

rose basalt
#

Don‘t nest event listeners. Make one interactionCreate listener and have it dispatch the event (which you probably already do for slashcommands).
But the way you do it atm you‘ll make a new listener every time someone creates a ticket, resulting in way too many listeners running simultaneously.

low lava
#

Yeah. Just refactor your handler to don't spam it and handle both slash commands and buttons

#

Like "if is button, do claim/close logic. If is command, do command thing"

steady cloud
#

Ok, and how would the event listener for the button know which message to edit?

#

Or would it just know automatically?

rose basalt
#

<ButtonInteraction>.message is the message the button is on. Or <ButtonInteraction>.update will automatically edit that message

steady cloud
#

And the event listener would be outside of the slash commands listener correct?

#

Due to nesting

rose basalt
#

Or it would be literally the same listener. Since both are interactionCreate