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
- 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![email protected]
node v20.10.0
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.
add option
fetchReply: true
in line 20 and try again: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...)
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?
what's the type of
response
the interaction type is button, the embed that triggered it was from a modal submission.
response
belongs to the modal submission.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
That makes sense. I appreciate your help!
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 caseI understand. I appreciate your time, thanks again!
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:pr_draft: #10068 in discordjs/discord.js by monbrey created <t:1704243116:R> (review required)
fix: remove potentially erroneous check
Now it makes A LOT more sense XD. Thank you.
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 youI 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 interactionYes, 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
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
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)