#How do you relate multiple button
1 messages · Page 1 of 1 (latest)
I keep them separate. Discord.js already associates button interactions with the message they belong to, so when you reply or edit a button interaction, the message contents change. So what I do is define a CommandHandler and a ButtonHandler data type, where each one can output a message payload like you normally would, with content, embeds, files, etc.
Then when interactions come in, I trigger an event handler that reads the interaction and finds the correct button or command handler, then calls it's functions to get the response.
The Command/ButtonHandler data structures have a handle function and additional properties that define how the interaction is replied to in the main event handler.
Example.
Example button handler
A button that shows a different help topic. Belongs to the response from the /help command, but defined completely separately because buttons are technically their own interactions.
When defining a button in a command response you set a customId, which your button handler will also share.
That all makes sense. thank you!
Something that i'm still not getting is how to handle a case like lets say:
User A uses /help
bot sends back embed with two buttons
User B clicks on a button
I want to ignore user B's clicks because user A is trying to use that menu. How do i find the user associated with the original interaction?
Do i have to store that myself now?
If only user A is allowed to take action on the response, you could send the embed as ephemeral: true so it only shows up for user A.
Ah yeah that's fair
Eats the use case if i wanted someone to be able to configure something public but not have other people mess with it tho
Disappointing. I'll probably just have to store a reference to the original user myself it appears.
About a year ago button and menu interactions came with full interaction information, i'm disappointed that's no longer the case
thanks for the help
Np
I don't know if this is possible but you might be able to find user A by checking the button interaction's message and what it is replying to.
like fetching the message.reference.messageId? then pulling the author from that?
that does seem like it could work
If you're replying to a / usage then you probably won't be able to find anything but it's worth looking into something like that
To see if you can't go up the chain at all.
it is a slash command originally. it seems to me like that would work. Just a bit of an annoyance because it used to 'just work' so i was hoping i was just missing something easy in the new djs version
It's even more annoying because the original button or menu response after i send the slash command does contain the interaction data, its just the one after that don't... i think