Editing a pinned message?

Hello! I have a reply to an interaction that I'd like to edit at a later time. The ID of the reply is stored in my database, and then the message is pinned to save it:
interaction.reply("Message...").then( reply => {
var stored = reply.id;
reply.pin();
});
interaction.reply("Message...").then( reply => {
var stored = reply.id;
reply.pin();
});
At a later time in my code when a button is pressed, I want this message to update. So I fetch the pinned messages:
interaction.channel.fetchPinned();
interaction.channel.fetchPinned();
But at this point, I'm stuck. Is there a way to access the message by ID here so that I can edit it? The following doesn't seem to work:
interaction.channel.fetchPinned().then( messages => {
for(const [key, value] of messages)
{ //if I print messages here, I see a key=>value collection — but is there a better way to access the message by the ID I stored?
if(key == game.TURNMSG){
value.edit("Edited!");
//This doesn't edit the message...
break;
}
}
})
interaction.channel.fetchPinned().then( messages => {
for(const [key, value] of messages)
{ //if I print messages here, I see a key=>value collection — but is there a better way to access the message by the ID I stored?
if(key == game.TURNMSG){
value.edit("Edited!");
//This doesn't edit the message...
break;
}
}
})
4 Replies
d.js toolkit
d.js toolkit12mo 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 staff
t̴humper
t̴humperOP12mo ago
No description
ShompiFlen
ShompiFlen12mo ago
store an object with channelId and messageId properties so then you can just directly edit the message through client.channels.cache.get(channelid).messages.edit(messageid, newOptions) you dont need to fetch any messages that way
t̴humper
t̴humperOP12mo ago
Thank you! do you know if .edit() will work with embeds as well? like:
messages.edit(messageid, { embeds: [newEmbed] });
messages.edit(messageid, { embeds: [newEmbed] });
oh, I got it! thank you for the help KohaneBow !
Want results from more Discord servers?
Add your server