edit ephemeral embeds

I have an ephemeral embed which has one ActionRow with 3 Buttons (Which you can find in the attachment ). The left button triggers some dm messages to the interaction user. After answering the message it should update the ephemeral embed. I read the forum post i found about that topic but didnt quite understand how he could call
interaction.update({ephemeral: true, content: "stuff"})
interaction.update({ephemeral: true, content: "stuff"})
at all. Cause im not able to do so. PS: Im not calling any deferUpdate or deferReply beforehand. Let me explain my setup a bit more detailed: I read the interaction.message to get the embed and build a new embed on top of that
message = interaction.message; //Interaction is a ButtonInteraction

const embed = new EmbedBuilder(message.embeds[0]) //embeds[0] is the correct embed
.setFields([
{ name: "Team Ranks", value: "anotherValue" }
])
message = interaction.message; //Interaction is a ButtonInteraction

const embed = new EmbedBuilder(message.embeds[0]) //embeds[0] is the correct embed
.setFields([
{ name: "Team Ranks", value: "anotherValue" }
])
i tried to update the embed with the ButtonInteraction#update function which looks like that:
await interaction.update({ embeds: [embed] })
await interaction.update({ embeds: [embed] })
But i receive following error:
DiscordAPIError[10062]: Unknown interaction
at handleErrors (@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (@discordjs/rest/dist/index.js:786:23)
at async _REST.request (/home/torben/coding/MatchBuddy/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ButtonInteraction.update (discord.js/src/structures/interfaces/InteractionResponses.js:233:5)
at async InteractionCollector.<anonymous> (file://bot/src/slashCommands/init.ts:158:55) {
requestBody: {
files: [],
json: {
type: 7,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
type: 'rich',
title: 'Gespeicherte Suche',
fields: [Array],
description: 'Folgende Einstellungen wurden hinterlegt',
color: 3201601
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1155983696248176681/aW50ZXJhY3Rpb246MTE1NTk4MzY5NjI0ODE3NjY4MTpkSDczOWFXSDJnaDlxSnBGTlAwOEl0Zk1sdGNacm11RmhGNVRIRHhIVndINk1OQzBOaElROHF0NVIwZnlnaTgzSERUZE84czZYd213bU5vT29vMzY2cUM0UzBQc2VBZFdET1hEaDJvekFXbG9LUFl1ZG1Td0luN2pLR0dOYnVBTA/callback'
}
DiscordAPIError[10062]: Unknown interaction
at handleErrors (@discordjs/rest/dist/index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (@discordjs/rest/dist/index.js:786:23)
at async _REST.request (/home/torben/coding/MatchBuddy/node_modules/@discordjs/rest/dist/index.js:1218:22)
at async ButtonInteraction.update (discord.js/src/structures/interfaces/InteractionResponses.js:233:5)
at async InteractionCollector.<anonymous> (file://bot/src/slashCommands/init.ts:158:55) {
requestBody: {
files: [],
json: {
type: 7,
data: {
content: undefined,
tts: false,
nonce: undefined,
embeds: [
{
type: 'rich',
title: 'Gespeicherte Suche',
fields: [Array],
description: 'Folgende Einstellungen wurden hinterlegt',
color: 3201601
}
],
components: undefined,
username: undefined,
avatar_url: undefined,
allowed_mentions: undefined,
flags: undefined,
message_reference: undefined,
attachments: undefined,
sticker_ids: undefined,
thread_name: undefined
}
}
},
rawError: { message: 'Unknown interaction', code: 10062 },
code: 10062,
status: 404,
method: 'POST',
url: 'https://discord.com/api/v10/interactions/1155983696248176681/aW50ZXJhY3Rpb246MTE1NTk4MzY5NjI0ODE3NjY4MTpkSDczOWFXSDJnaDlxSnBGTlAwOEl0Zk1sdGNacm11RmhGNVRIRHhIVndINk1OQzBOaElROHF0NVIwZnlnaTgzSERUZE84czZYd213bU5vT29vMzY2cUM0UzBQc2VBZFdET1hEaDJvekFXbG9LUFl1ZG1Td0luN2pLR0dOYnVBTA/callback'
}
No description
18 Replies
d.js toolkit
d.js toolkit9mo 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
Sim3Xx
Sim3Xx9mo ago
Node: v20.6.1
No description
duck
duck9mo ago
your error just means that your bot didn't respond to the interaction in time (within 3 seconds) since you're taking some actions that could potentially take time, you'll want to use <ButtonInteraction>.deferUpdate() as soon as possible beforehand then you can use <ButtonInteraction>.editReply() afterwards when you're ready to actually update the message
Sim3Xx
Sim3Xx9mo ago
So the creation of the embed is a different one than the one that tries to update the embed is that a problem? if i try to deferUpdate the answer it says:

discord.js/src/structures/interfaces/InteractionResponses.js:225
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
^

Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.update (discord.js/src/structures/interfaces/InteractionResponses.js:225:46)
at InteractionCollector.<anonymous> (file://bot/src/slashCommands/init.ts:159:73)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'InteractionAlreadyReplied'
}

Node.js v20.6.1

discord.js/src/structures/interfaces/InteractionResponses.js:225
if (this.deferred || this.replied) throw new DiscordjsError(ErrorCodes.InteractionAlreadyReplied);
^

Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ButtonInteraction.update (discord.js/src/structures/interfaces/InteractionResponses.js:225:46)
at InteractionCollector.<anonymous> (file://bot/src/slashCommands/init.ts:159:73)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
code: 'InteractionAlreadyReplied'
}

Node.js v20.6.1
duck
duck9mo ago
the issue on its own is simply that it took too long it's likely unrelated to the embed you're creating, but more so the dms you're sending
then you can use <ButtonInteraction>.editReply() afterwards when you're ready to actually update the message
Sim3Xx
Sim3Xx9mo ago
Okay, i dont really understand why but i works now. I first tried to fetch the ephemeral message and try to edit it that way by calling
const message = await interaction.channel.messages.fetch(embedMessageId.id)
const message = await interaction.channel.messages.fetch(embedMessageId.id)
which has been the first error i did i think Thanks that solves it Absolutly my bad blobsweats you have like a list with all the meanings for the discordApi error messages? Sry for disturbing IdkWhatToSay
duck
duck9mo ago
just to clarify, the issue with this approach is that ephemeral messages can only be fetched/edited/deleted through the interaction webhook
Sim3Xx
Sim3Xx9mo ago
That was the missing piece. Thank you very PepeNoted
duck
duck9mo ago
I mean in many cases there isn't one specific meaning for each error message - "Unknown interaction" only has the one cause of "it took too long", but as you can imagine, there can be many reasons for your bot to take too long to do just about anything - I'd hope that "The reply to this interaction has already been sent or deferred." is pretty self explanatory - "Unknown message", the error you would receive from fetching an ephemeral message, is also basically exactly what it says: discord doesn't know of the message you're trying to fetch it'd be because ephemeral messages aren't exactly in the channel the same as normal messages
Sim3Xx
Sim3Xx9mo ago
Can you only edit an ephemeral message if the message itself triggers an interaction or with any interaction as long as you have the messageId?
duck
duck9mo ago
you're able to use editReply as many times as you like (within reason for rate limits) within the 15 minute lifespan of the interaction's token it can be used to edit ephemeral messages including ephemeral follow ups
Sim3Xx
Sim3Xx9mo ago
So i can only edit those embeds with an interaction triggered by exact that message that i want to update/edit? (If you have like buttons in that message or other messageComponents)
duck
duck9mo ago
no, again you can use editReply to edit an ephemeral follow up but if you're asking whether you can just edit an ephemeral message at any point in time all the time, the answer is no
Sim3Xx
Sim3Xx9mo ago
sry im still not catching up... I used a command to get messages sent to my dms. The result creates the first instance of the ephemeral embed. Next step would be clicking on the button "Einstellungen ändern" which again triggers the same messages as before to update the embed. Do you call this type of scenario a follow up? Im kinda confused As of my understanding its a different interaction
duck
duck9mo ago
no, "followup messages" can be sent after the initial response to the interaction (reply, update, etc) you would use <Interaction>.followUp() to send a followup message
Sim3Xx
Sim3Xx9mo ago
Oh didnt know that. So if you create something from an initial response its still the same interaction? Interesting That helps a lot!
duck
duck9mo ago
👍
Sim3Xx
Sim3Xx9mo ago
Thank you so much! Saved me so much PETTHEMODS can see the light at the end of the dark tunnel now