Adding reactions to embed message.
Hello there. I am trying to add reactions to a message my bot sends but for some reason react() doesn't exist for me. I have tried a couple of different ways but everything I try doesn't work. I have a which is later used like this I tried adding a but it just says it doesn't exist. I also tried with a .then but also does not work. Adding it to the embed directly obviously also doesn't work.
21 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!You need to assign it to a variable and then use that (may also need to add fetchReply: true to your options)
const foo = await ...; foo.react(...)
Resources to understand Promise:
- MDN: learn more
- Guide: learn more
- JavaScript info: learn more
Tried
Didnt work always tries to make it to reactions()
But even when the IDE changes it to reactions it throws an error
The guide page I linked above covers the use case of reacting to a message using await https://discordjs.guide/additional-info/async-await.html#how-to-implement-async-await
And that's not what I meant by adding fetchReply to your options
I am aware but and then the rest also doesn't work. Saw the guide... didnt work
how didn't it work
Because just randomly changing stuff isn't going to fix what you did wrong
And the guide code has been tested to work as written, and it can be adapted to other use cases
I went through docs and guids everything that I tried didnt work so I came here
So the code generally works and it's a massiv bot with about 40 commands but I was trying to add something new
Again: you may need to add fetchReply: true to your reply options
Hope this is what you meant
Ahh typescript, how I despise you
Hahaha, I think I should recode the bot in another language lol
Try using the interaction.inCachedGuild() type guard ahead of that so TS knows it's in a cached guild, that should give you the message
Just checking if I understand correctly. I am assigning interaction.isCachedGuild to const message
Or just writting it into the code by itself
since interactions can come from DMs or (uncached, in the case of user apps) guilds, TS has no way of knowing without you specifying, and that's why the guard is needed
So interesting fact. I added interaction.inCachedGuild() just like that in the code, no error. Then added it in the if, showed a error that it doesn't exist. Copied the working part into the if (code didnt change) it shows as no error.
Added the if but react still shows with same error
Ahh wait
I think I got it to work
Why is typescript so complicated sometimes for no reason.
it can be a pain to work with at first, but if you look at it logically, it makes sense. like i said, there are multiple possibilities for where the interaction is coming from, one event covers all of them, so there's no way to know ahead of time where it's from and type it more strictly, so we need to keep the interaction type/properties more broad, then narrow it down by telling the ts server where it's coming from