Passing down arguments of Commands to the Interaction Handlers
I have a command that takes a user argument like
/clan member @MindLabor
and this command creates a message with Buttons. I also have a button interaction handler which runs when the button is clicked. But in that interaction handler I cannot find the arguments of my original command that created the message. Is there a good way of "passing" the data from where the buttons are built to the handler?
Button Message Creation:
Button Handler
Solution:Jump to solution
That way, my button handler can check if the label starts with the
unique-label
, then I can checke if the user who clicked the button matches the user who requested the button, and finally I get whatever other information I need to actually preform the action (in your case that looks like it owuld be another userID)4 Replies
The best way I've found is to pass information through the custom ID's themselves. I usually use the format of
unique-label|userId-that-requested-button|extra-info
Solution
That way, my button handler can check if the label starts with the
unique-label
, then I can checke if the user who clicked the button matches the user who requested the button, and finally I get whatever other information I need to actually preform the action (in your case that looks like it owuld be another userID) there is no real other way with the Discord API.
The only alternative is having a
Map
that you export from somewhere then write keys to it and read from it in the handlers. Basically dependency injection.ah I see, will do for my purpose
that hurts my soul but I'll keep it in mind xD