#Need help with buttons

50 messages · Page 1 of 1 (latest)

dim lily
#

how to send a message with a set of buttons (set 1) and upon clicking a button, the message gets edited with a new set of buttons (set 2), and make set 2 functional? I have tried stuff like creating new collector, trying to collect the customId of set 2 in the same collector for set 1 but nothing works. My code currently is like https://sourceb.in/RBjdTmvmJB

spiral charmBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by OP
blissful crest
#

there's many ways to achieve this, including using a second collector
putting aside the fact that the section with the second collector is currently commented out, it seems as though you're accessing the nonexistent matchResponse, and you may also run into some scoping issues regarding confirmation in your catch block
please put together something you believe would work, then we can work through why it doesn't

dim lily
#

matchResponse was initially defined as sending a new message upon clicking start button and it was supposed to be editing the new message upon choosing a move, since it didn't work I commented it out and tried editing the initial message using same collector for all buttons

blissful crest
#

well awaitMessageComponent, the promisified component interaction collector, only collects one component interaction and resolves when it's done so
if you wanted to handle everything with one collector, you'd need to use the standard event-based collector createMessageComponentCollector

dim lily
#

hmm, I think I'll go with 2nd collector itself

blissful crest
#

just as a note, <Interaction>.reply() resolves in an InteractionResponse if you don't specify fetchReply: true, and collectors created from InteractionResponses currently have a couple issues
I believe this case may not run into them, but for most cases it's recommended to specify fetchReply: true so that it resolves in the Message sent instead

dim lily
#

seems more neat

dim lily
#

using 2nd collector

#

right now the issue is, it edits the initial message and sends a new message with embeds and attack component but

#

it only accepts the first click

#

any click after that leads to interaction failed message

#

there's no error in console

blissful crest
#

the first click as in the start/cancel buttons?

#

or the first click of each of punch/kick/surrender?

blissful crest
#

that's because as mentioned, awaitMessageComponent only collects one component interaction
if you want to use a collector to handle more than one, you'd need to use the standard event-based collector createMessageComponentCollector

dim lily
#

ohhh

#

is there any guides for that?

delicate nimbusBOT
#

guide Popular Topics: Collectors - Interaction collectors
read more

dim lily
#

alright

blissful crest
#

(it's roughly the same options as awaitMessageComponent)

dim lily
#

so you are suggesting I should use createMessageComponentCollector for punch/kick/surrender row right?

blissful crest
#

sure

dim lily
#

okay thanks! I'ma try it

dim lily
#

if I give time parameter as 30_000

#

will it collect only for 30s or it will start the timer after every click

blissful crest
#

the time option is just a standard time limit
if you want it to reset each time the collector collects something, you should use the idle option

delicate nimbusBOT
dim lily
#

ohh

#

oke

dim lily
blissful crest
#

putting aside how awkwardly message appears to be defined, <TextChannel>.send() is asynchronous
you were previously awaiting it

#

<Interaction>.followUp() also exists and sends a follow up message through the interaction webhook if you'd prefer to go through the interaction

dim lily
#

I didn't know that

dim lily
crude peak
#

not message

dim lily
#

well I did something and its working now

#

oh there's 2 collect events

#

lemme remove one

crude peak
#

nice

dim lily
#

well I have a javascript doubt but dont feel its worth making a post

#

so I'll ask here

#

how do I import functions and use from other files?