Get message by ID and then update it

I tried this but .update does not exist
await interaction.channel.messages.fetch(messageId).update(toSend);
await interaction.channel.messages.fetch(messageId).update(toSend);
19 Replies
d.js toolkit
d.js toolkit5mo 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! - Marked as resolved by OP
okunamayanad
okunamayanadOP5mo ago
npm list discord.js
[email protected] /home/baran-mordo-an/vote
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js
[email protected] /home/baran-mordo-an/vote
└── [email protected] -> ./node_modules/.pnpm/[email protected]/node_modules/discord.js
node -v
v20.15.0
v20.15.0
Mark
Mark5mo ago
Fetch returns a promise
Benluka.dev
Benluka.dev5mo ago
very first you need to await or use then
Mark
Mark5mo ago
update also doesn't exist on a message It's a method on an interaction
okunamayanad
okunamayanadOP5mo ago
oh I used await sorry accidentally cut that off
await interaction.channel.messages.fetch(messageId).update(toSend);
await interaction.channel.messages.fetch(messageId).update(toSend);
Benluka.dev
Benluka.dev5mo ago
that still won't work I assume. The update should go on next line
Mark
Mark5mo ago
This is why you don't one line promises
Benluka.dev
Benluka.dev5mo ago
it's edit also
Mark
Mark5mo ago
If you don't need the message content or anything prior, you can just do channel.messages.edit()
d.js docs
d.js docs5mo ago
:method: MessageManager#edit() @14.15.3 Edits a message, even if it's not cached.
Mark
Mark5mo ago
Don't need to fetch it first
okunamayanad
okunamayanadOP5mo ago
what? dont i still need the message to put it to first argument of edit? or does that work with a message id too? let me try
Mark
Mark5mo ago
Of course you don't need the full message object, that would defeat the purpose of it being able to edit uncached messages
okunamayanad
okunamayanadOP5mo ago
so I'm trying to edit an embed and replace that with another
await interaction.channel.messages.edit(messageId, {
components: [ActionRowBuilder<AnyComponentBuilder>],
files: [AttachmentBuilder],
embeds: [EmbedBuilder]
});
await interaction.channel.messages.edit(messageId, {
components: [ActionRowBuilder<AnyComponentBuilder>],
files: [AttachmentBuilder],
embeds: [EmbedBuilder]
});
so this should work right? my IDEs complaining about the types mismatching though and when I checked the types I couldn't figure out how would I edit an embed with files and components
Mark
Mark5mo ago
What's it saying is wrong
okunamayanad
okunamayanadOP5mo ago
is not assignable to parameter type string | MessagePayload | MessageEditOptions anyways i'll try it anyways and see if thats an IDE issue doesn't look like a one tho, because its correct when I check the docs
Mark
Mark5mo ago
I think it's attachments when editing The message edit options don't agree with the message payload I'm not super well versed in this part, sorry
okunamayanad
okunamayanadOP5mo ago
even though my IDE complains about stuff, it works fine! tysm @Mark
Want results from more Discord servers?
Add your server