Getting original userID of slash command via Button Interaction
Hey, so I'm using a button Handler. But everyone can interact with the button. How do I restrict the button to be usable by the user who ran the slash command from which the button originated? (I use the
interactionCreate
event to reply to the buttons, so I can only get the buttonInteraction). I don't wanna use db20 Replies
you will have to associate the original author with the button, somehow
if you are just looking for confirm buttons, i'd probably recommend using a component collector in the scope you have "original author" available and supplying it as a filter condition.
if this is happening in another scope, you still need to somehow know who triggered the original response, either via in-memory map or by having the user id in the custom id and parsing it from there
You can always use ephemeral responses so only the user can see it
or another option is what Souji stated
You could cache the response with something like
userID: messageID
Basically associating the button to specifically that user via that message itself and then if someone clicks that button, you can check if that user is associated with that button
and if not, handle it with what you preferI was looking for a solution for non-ephemeral responses
how do I cache the response?
by cache I mean like
store it in memory
You can have a collection
and add it to them
and them remove it after x minutes etc
but doesn't collection clear on restart?
I'm not sure how to store in memory..
yes it does
then you need a db to store it
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I really wish I could use that, but since I use a button handler, I'll have to handle the buttons like
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I mean yea, but how would I access
interaction
when it's defined after customId
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
I didn't figure it.. I tried
this
didn't workUnknown User•3y ago
Message Not Public
Sign In & Join Server To View
nvm, I got it. Just had to change my command handler a bit
@polar.phoenix Why not just use a file storing db
If you need to store these buttons for really long times then maybe not the best call but
you can always use a JSON file storing method for it if you want
u want to get user which invoked interaction with button?
so <buttonInteraction>.message.interaction.user.id
ah, finally. Thank you
Unknown User•3y ago
Message Not Public
Sign In & Join Server To View
yeah