Need help with buttons

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
28 Replies
d.js toolkit
d.js toolkit11mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - 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
duck
duck11mo ago
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
ItzDaSrijan
ItzDaSrijanOP11mo ago
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
duck
duck11mo ago
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
ItzDaSrijan
ItzDaSrijanOP11mo ago
hmm, I think I'll go with 2nd collector itself
duck
duck11mo ago
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
ItzDaSrijan
ItzDaSrijanOP11mo ago
seems more neat hm I've made modifications to the code: https://sourceb.in/XyWzf8GU9h 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
duck
duck11mo ago
the first click as in the start/cancel buttons? or the first click of each of punch/kick/surrender?
ItzDaSrijan
ItzDaSrijanOP11mo ago
this one
duck
duck11mo ago
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
ItzDaSrijan
ItzDaSrijanOP11mo ago
ohhh is there any guides for that?
d.js docs
d.js docs11mo ago
guide Popular Topics: Collectors - Interaction collectors read moremethod Message#createMessageComponentCollector() Creates a message component interaction collector.
ItzDaSrijan
ItzDaSrijanOP11mo ago
alright
duck
duck11mo ago
(it's roughly the same options as awaitMessageComponent)
ItzDaSrijan
ItzDaSrijanOP11mo ago
so you are suggesting I should use createMessageComponentCollector for punch/kick/surrender row right?
duck
duck11mo ago
sure
ItzDaSrijan
ItzDaSrijanOP11mo ago
okay thanks! I'ma try it btw if I give time parameter as 30_000 will it collect only for 30s or it will start the timer after every click
duck
duck11mo ago
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
d.js docs
d.js docs11mo ago
interface CollectorOptions Options to be applied to the collector.
ItzDaSrijan
ItzDaSrijanOP11mo ago
ohh oke
duck
duck11mo ago
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
ItzDaSrijan
ItzDaSrijanOP11mo ago
I didn't know that how should I define it I have no idea
mushtaq
mushtaq11mo ago
why dont create message component collectar using interaction not message
ItzDaSrijan
ItzDaSrijanOP11mo ago
well I did something and its working now https://sourceb.in/Ue7AZT3d07 oh there's 2 collect events lemme remove one
mushtaq
mushtaq11mo ago
nice
ItzDaSrijan
ItzDaSrijanOP11mo ago
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?
treble/luna
treble/luna11mo ago
thats basic js, #rules 3 #resources
Want results from more Discord servers?
Add your server