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
interaction: CommandInteraction
interaction: CommandInteraction
which is later used like this
await interaction.reply(pingRole);
await interaction.editReply({content: null, embeds: [embed]});
await interaction.reply(pingRole);
await interaction.editReply({content: null, embeds: [embed]});
I tried adding a
interaction.react()
interaction.react()
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
d.js toolkit
d.js toolkit3w ago
- 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!
Mark
Mark3w ago
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(...)
d.js docs
d.js docs3w ago
Resources to understand Promise: - MDN: learn more - Guide: learn more - JavaScript info: learn more
Deadlyapple
DeadlyappleOP3w ago
Tried
const message = interaction.fetchReply();
(await message).react()
const message = interaction.fetchReply();
(await message).react()
Didnt work always tries to make it to reactions() But even when the IDE changes it to reactions it throws an error
Property 'reactions' does not exist on type 'Promise<APIMessage | Message<boolean>>'.
Property 'reactions' does not exist on type 'Promise<APIMessage | Message<boolean>>'.
Mark
Mark3w ago
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
Deadlyapple
DeadlyappleOP3w ago
I am aware but
const message = await interaction.reply(pingRole);
const message = await interaction.reply(pingRole);
and then the rest also doesn't work. Saw the guide... didnt work
Mark
Mark3w ago
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
Deadlyapple
DeadlyappleOP3w ago
I went through docs and guids everything that I tried didnt work so I came here
No description
No description
No description
Deadlyapple
DeadlyappleOP3w ago
So the code generally works and it's a massiv bot with about 40 commands but I was trying to add something new
Mark
Mark3w ago
Again: you may need to add fetchReply: true to your reply options
Deadlyapple
DeadlyappleOP3w ago
Hope this is what you meant
No description
Deadlyapple
DeadlyappleOP3w ago
Property 'react' does not exist on type 'APIMessage | Message<boolean>'.
Property 'react' does not exist on type 'APIMessage'
Property 'react' does not exist on type 'APIMessage | Message<boolean>'.
Property 'react' does not exist on type 'APIMessage'
Mark
Mark3w ago
Ahh typescript, how I despise you
Deadlyapple
DeadlyappleOP3w ago
Hahaha, I think I should recode the bot in another language lol
Mark
Mark3w ago
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
Deadlyapple
DeadlyappleOP3w ago
Just checking if I understand correctly. I am assigning interaction.isCachedGuild to const message Or just writting it into the code by itself
Mark
Mark3w ago
if (interaction.inCachedGuild()) {
// do stuff
} // optional else block
if (interaction.inCachedGuild()) {
// do stuff
} // optional else block
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
Deadlyapple
DeadlyappleOP3w ago
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
Deadlyapple
DeadlyappleOP3w ago
No description
Deadlyapple
DeadlyappleOP3w ago
Ahh wait I think I got it to work Why is typescript so complicated sometimes for no reason.
Mark
Mark3w ago
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
Want results from more Discord servers?
Add your server