#handling multiple button clicks on collector

1 messages · Page 1 of 1 (latest)

little plover
#

hey

mint ingot
#

oh

#

hi

#

thanks for helping by the ways

#

appreciate it

little plover
#

i don't know if you intend to add dropdowns to this or whatnot, but it's good practice to check if the reaction is a button before doing anything else

mint ingot
#

cant find anything in there atm though

little plover
#

and then inside those, you can check for the custom ids and handle each one accordingly

little plover
mint ingot
#

oh my god

#

thanks

little plover
#

make sure you remove that id checking from your filter first

#

go through this again with me, you want to handle multiple button clicks?

#

your handling edits out the buttons out of the message entirely, so a second button can't be pressed

#

do you still wish to handle multiple button clicks?

mint ingot
#

does this look right?

        collector.on('collect', async i => {
          if(i.isButton()){
            if(i.customId === 'athrust'){
              await i.update({ content: 'pressed thrust', components: [] });
            }
          }
          
        });```
little plover
#

i don't know if that's gonna work because the i interaction is a button press, so i don't think there will be a message to be updated?

mint ingot
#

oh wait, but for "filter" i had const filter = i => i.customId === 'athrust' && i.user.id === '842573885076406283';

little plover
#

i assume you want to edit the original message that has buttons, right?

little plover
#

this filter assumes that only the interaction user will click the buttons. other users will get 'interaction failed' error. make sure your users understand that's normal for them to be nosy on someone else's command

mint ingot
#

thanks!

#

thank you so much!

rain wren
#

the answer to your initial issue was much easier, you just had to add both options to the filter, like this

const filter = i => (i.customId === "poke" || i.customId === "pinch") && i.user.id === '842573885076406283'; then in the collector update the message accordingly

little plover
#

you would be checking the customId again inside the collector, that's just more code to do the same thing

mint ingot
#

yeah, i see

rain wren
#

it would've been one if statement to separate both if (b.customId === "pinch"){}else{}

#

I dont see how much more code is that cirno_shrug

little plover
#

there is no need to check for the value twice, which is what your suggestion does

mint ingot
little plover
#

do you have the original message object?

#

are you getting the message from a slash command reply or a message create?

mint ingot
#

oh nevermind - this works

#

collector.on('end', async i => {interaction.editReply({content: `okay, time's up.`, components: []})});