Help collecting a button component

Hey guys, I have been struggling trying to collect a button response. I am following the "component collectors" portion of the tutorial: https://discordjs.guide/message-components/interactions.html#component-collectors For whatever reason my collector isn't triggering when I press any of the buttons. Here are the relevant portions of code: https://pastebin.com/dsUgMDM0 There are no errors in console, nor does the bot crash. Through some console.log trial and error I have determined that the process functions properly all the way up to ln.23 -> collector.on().
Pastebin
const { SlashCommandBuilder, EmbedBuilder, ModalBuilder, TextInputB...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
20 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!
BoxWithout
BoxWithoutOP11mo ago
[email protected] node v20.10.0
BoxWithout
BoxWithoutOP11mo ago
with .js syntax highlighting: https://pastebin.com/c6xJQJFN
Pastebin
const { SlashCommandBuilder, EmbedBuilder, ModalBuilder, TextInputB...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Bloonatics
Bloonatics11mo ago
add option fetchReply: true in line 20 and try again
d.js docs
d.js docs11mo ago
:class: InteractionCollector (extends Collector) Collects interactions. Will automatically stop if the message (Client#event:messageDelete messageDelete or Client#event:messageDeleteBulk messageDeleteBulk), channel (Client#event:channelDelete channelDelete), or guild (Client#event:guildDelete guildDelete) is deleted. (more...)
BoxWithout
BoxWithoutOP11mo ago
That was it! Thank you! Would you happen to know why that isn't included in the tutorial? Is there something specific about my code that requires that?
Bloonatics
Bloonatics11mo ago
what's the type of response
BoxWithout
BoxWithoutOP11mo ago
the interaction type is button, the embed that triggered it was from a modal submission. response belongs to the modal submission.
Bloonatics
Bloonatics11mo ago
take a look at this https://github.com/discordjs/discord.js/blob/main/packages%2Fdiscord.js%2Fsrc%2Fstructures%2FInteractionCollector.js#L154-L160 you should have a message id filter instead of a message interaction id filter, so call .createMessageComponentCollector() on a Message instead of a InteractionResponse in this case
BoxWithout
BoxWithoutOP11mo ago
That makes sense. I appreciate your help!
Bloonatics
Bloonatics11mo ago
the interaction type is CommandInteraction in the guide, i.e. they only want to collect interactions when MessageInteraction#id matches the original application command interaction id your case is a ModalSubmitInteraction, so that's not their case
BoxWithout
BoxWithoutOP11mo ago
I understand. I appreciate your time, thanks again!
duck
duck11mo ago
just to elaborate, the reason this wasn't included in the tutorial is that this is due to a bug it's not intended behavior for it to require you to fetch the Message collectors are supposed to be able to be created from an InteractionResponse the solution for this issue is still a WIP
GitHub
GitHub11mo ago
:pr_draft: #10068 in discordjs/discord.js by monbrey created <t:1704243116:R> (review required) fix: remove potentially erroneous check
BoxWithout
BoxWithoutOP11mo ago
Now it makes A LOT more sense XD. Thank you.
Bloonatics
Bloonatics11mo ago
actually you don't have to fetch the message, just call the InteractionCollector constructor it's just because the current InteractionResponse#createMessageComponentCollector() applied an unnecessary filter for you
duck
duck11mo ago
I mean the method used for creating the collector isn't exactly the issue it's more how the InteractionCollector resolves which message to collector from it's also not an unnecessary filter the object you call createMessageComponentCollector on is supposed to restrict from where component interactions are collected if you're referring to the pr, you may want to read the whole thing including the part that mentions it not being an erroneous check tldr the issue is more complicated than it seems at first glance, and while it's true that you can get around some cases of this issue by instantiating InteractionCollector yourself, several cases would need you to work with some extra data yourself not necessarily provided by the collected interaction
Bloonatics
Bloonatics11mo ago
Yes, this post is just related to a wrong use of that method. They don't have to fetch the message for its id when they already have it. wait, the reply is a new message
duck
duck11mo ago
yes, and discord doesn't send response data for the initial interaction response therefore they don't have the id therefore it needs to be fetched which is to say, your initial solution was correct I was just here to explain why
Bloonatics
Bloonatics11mo ago
ok we all got it. this is another reason for people to actually spend some time to read the djs code from github to understand it better (docs and guide aren't enough)
Want results from more Discord servers?
Add your server