Issue understanding collector filters
Hi all, I was recently working on learning and integrating collector filters for my code so that if a user who didnt start the interaction tries to press a button reply, it wont work for them. I believe what I need is a collector filter. Based on the discord.js guide and documentation I tried to set one up like this:
The code runs as intended and I thought it was working fine, however when testing with a second person they were able to use the button responses. I can provide more code if needed but I think Im misunderstanding a fundamental part of filters.
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!that collector is 100% not running for other users
The collector is on the main script for a slash command, I ran the command myself and the buttons appeared. I have someone next to me in real life click one of the buttons on my interaction on their discord account and it ran for them sucessfully even though it was my accounts interaction.
that componenttype is incorrect
RangeError [BitFieldInvalid]: Invalid bitfield flag or number: undefined
- All SCREAMING_SNAKE_CASE
enums have been changed to PascalCase
- Intents: Intents.FLAGS.GUILD_MESSAGES
-> GatewayIntentBits.GuildMessages
- Permissions: Permissions.FLAGS.SEND_MESSAGES
-> PermissionFlagsBits.SendMessages
If you are waiting for button or select menu input from a specific message, don't create the collector on the channel.
- Channel collectors return component interactions for any component within that channel.
Are you saying I should replace to = interaction.message.createMessageComponentCollector ?
Or do you mean the componenttype where I have the button?
Sorry, just trying to clarify what you mean. It seems I should have the collector be only for the interaction and not the channel, but if I change it to interaction.message I start getting typeerrors.
attach it to the message your buttons are attached to
Oh wait ok, sorry, I'm self taught and really bad with terminology. Based on what you said I assume that line means I'm attaching the collector to the interactions channel and not to the interaction message itself and that's why others can respond? And by setting the collector instead to the actual interaction message it'll achieve the desired effect?
Sorry, just wanting to make sure I understand the logic so I can stop myself from making the mistake in the future.
not sure why its responding but it might fix it
also note the other thing i said, its not BUTTON, its Button
I kept it as interaction.channel.createMessageComponentCollector and ONLY changed BUTTON to Button...that did the trick! I'm getting some other unrelated error now but I can solve that one. Thanks for the help 🙂
Actually did not solve, seemed to at first. But I will keep as 'Button' and attempt to attach the collector instead to the message as recommended.
As far as I'm aware my code already should be attaching the collector directly to the interaction, so
If thats only attaching it to the channel the buttons are in, whats the correct way to do it? I'm not logging any errors when it runs as posted, but others are able to respond regardless of the filter.
attach it to the message the buttons are attached to
I understand you're saying to do that - I'm not sure how. From what I've read even after your reply, I'm still of the mind that my code should already be attaching it directly to the interaction message. Obviously that's not working, so I'm trying again to re-read the documentation.
show your full code
because now you're attaching to the channel, not the message
This is the full code, relevant collector lines start at around line 85
Should I store the editReply message in a variable and set collector to that?
yep
also that code still has BUTTON
Sorry, ctrl+z'd a bit much. Was setting up to store message. One sec.
Does that look correct for setting it to the message as opposed to channel?
that looks good
I would assume, just looks too easy! lol. Thanks, gonna test it thouroughly here.
Tested with 4 accounts this time. Seems to have worked nicely! Thank you again @wolvinny🌈 for being patient with me. I understand what I messed up well enough to hopefully avoid it in the future! 🙂
awesome!