Reaction Listener bot help needed
I have this bot that I want to do these things. I want it to send an embed on command, react to it, then listen to user reactions and log those reactions in another channel.
Things I am having trouble figuring out is:
1. the embed sends twice when the command is sent for what i have no idea
2. i would like to make it so that the user can only input one reaction at a time. so that if a user changes their reaction, their old one is removed.
3. i would like the bot to automatically remove any reactions that are not the same emoji as the ones the bot reacted to itself with.
Any help is appreciated. I am brand new to v14 and I am having trouble figuring this out, so talk to me like I know nothing. Thank you!
23 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 OP1. Are you only running 1 instance of the bot?
2. You can get a cache of message reaction users with
message.reactions.cache.users
, see if the users who reacted to the new reaction has previously reacted to any other reactions, you can remove their other reactions with message.reactions.cache.users.remove()
3. Use the messageReactionsAdd
event to see if the reaction is being added to your embed, and if it's not a reaction you want added, remove it with messageReaction.remove()
Further, on the third line, it should be message.author.id !== '00000000'
because !message.author
will always be false. I assume that ID is your bot ID and you want it to not reply to itself?that third line is just i want to be the only person able to use the command
yes, i think im only running one instance, i just node . when i need to test something
do you think you could write small code snippets as examples? i cant find resources on this and because of how new i am im not able to write completely on my own yet. sorry if im asking too much
@probablyraging 🍄
Right, I get that, but your condition is incorrect
(!message.author === '00000000')
- is basically saying "if message.author is false and equal to '0000000' then return" which is not doing what you want it to do because that statement !message.author is always going to false so the entire condition will always be false
(message.author.id !== '0000000'
- is saying "if message.author.id is not equal to '0000000'" then return" which is what you want it to do
No I'm not going to write your code for youokay, well this helps
any idea on why the embed sends twice or no? based off the code already written
Only thing I can assume is either the incorrect condition or you've got 2 instances running somehow
alright, i'll troubleshoot those two things
:property: MessageReaction#users
A manager of the users that have given this reaction
:method: ReactionUserManager#remove()
Removes a user from this reaction.
:event: (event) Client#messageReactionAdd
Emitted whenever a reaction is added to a cached message.
Those links should help too. I'll be around for a while so have a crack at it yourself and if you need help, just ping me
sounds good
yeah i dont know what the hell i did but now the bot wont send ANYTHING at all
or even console log that its recieved anything
@probablyraging 🍄
i havent changed really anything...
just tried fixing the issue where it was sending twice
i closed every instance and now after i restarted it, nothing happens
i checked and the user id isnt wrong
message.author.id
not message.author
Line 5oh for fucks sake
it sends the embed only once now, but now it doesnt add its reactions
Should full code again, use https://pastebin.com/
Pastebin
Pastebin.com - #1 paste tool since 2002!
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.
Pastebin
code - Pastebin.com
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.
Can't see anything wrong with that, does the bot have perm to add reactions?
it does
it was working just a bit ago
i fixed it by changing it to this
instead of having it on one line
which is annoying that i had to do this
Oh yeah, I just seen you were using
[]
brackets instead of ()
on PvP.react
, react is a function so should be react('🧁')
for exampleah i see
what function would i use if i wanted to just have my code wait like 10 seconds before sending the log in the other discord channel? @probablyraging 🍄
i swear i thought it was setTimeout but that isnt working
You can use setTimeout
:mdn: setTimeout() global function
The global setTimeout() method sets a timer which executes a function or specified piece of code once the timer expires.
If you mean you want the rest of the code to wait before executing, you can use setTimeout in a Promise
Like so
new Promise(resolve => setTimeout(resolve, 1000))