Automatic reactions
so here I am, with another query. How would I go over making it so upon modal submission there would appear two reactions, checkmark and x and if either is clicked, it makes an appropriate action?
I thought just right now that I would have to add reactions right in my modal code so when its sending the whole embed it also adds reactions but how would it listen to it? I need to really get a grasp of it but im having trouble with it
15 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!
- ✅
Marked as resolved by OPIn the code where you send you embed is where you should add the reactions
Then you can either add a collector to that message to listen to user's reacting to it, or use the
messageReactionAdd
eventyeah but lets say i dont want my bot to misexecute, i mean like take reaction from some entirely different message and execute it, how would i go over making it so it only does collect it from that one specific channel and retreive the user who submitted it
Depends how you're handling the reaction click. With a collector it will be attached to
embedMessage
so only reactions on that message will be filtered
If you're doing it through the messageReactionAdd
event then you would need to check if the id of the message being reacted to is the correct message idwont like collector expire after certain amount of time if i do all that after embed
I'm pretty sure you can run a collector indefinitely or until the bot stops, unless you set an expire time yourself
If you need a more permanent solution you can either fetch that message when your bot starts and add the collector again, or just use the event and store the message ID
Assuming that you're giving the user some additional options after submitting a modal, I don't see why you would need to have a perpetual collector though. Just dispose of the collector (and message) once the user makes their choice
ok so
the modal is like an application
they submit it once they never see it again
and i want then to be able to react with yes or no without having 20 minutes or so before collector ends
so about storing it, where would it be better to do so?
Probably a collector, with an expire time of 20 minutes then. Once that time elapses do what you need to with the data and then delete the message
Though again, that collector will be deleted if the bot disconnects for any reason, and 20 minutes is a long amount of time to give a person to react to something. I would say like 15 seconds max to minimize any issues
yeah but i wont always be there to accept or reject the application within 20 minutes
Yeah that doesn't really sound like a practical use case in general. Maybe a better idea would be to store their application data somewhere (like a database), and then have a separate function for fetching and approving/denying applications altogether
Or just have them use a Google form lol
alright ill see in few hours what i can do, thanks for your help
actually acnt i just run collector infinitely
you said as long as my bot is on, right?
if it shuts down, after restart, it wont work but if bot is on then collector will just work
right?
That's correct
But again, if you receive an application and send the message with the reactions and the bot stops/restarts for any reason, you won't be able to use that collector unless you reattach one
For what it's worth, buttons are the superior solution here, no need to worry about cache, you'll always get the interaction
I wouldn't use collector for your specific use case, you are saying that you only want to listen to message reaction add in specific channel, so just listen to that event and if the reaction added is not on a message in that channel just ignore, otherwise do the logic there. No need to use database/collectors. Also what the guy above me said ^
so button because customid... right?
i forgot about that
alright thats a solution, thank you