Embed editting

Hello all, I have been trying to get an embed field to edit once a button is clicked is this possible ?
12 Replies
d.js toolkit
d.js toolkit7mo 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
treble/luna
treble/luna7mo ago
<ButtonInteraction>.update() with your edited embeds
JoelHCraft
JoelHCraft7mo ago
I have this :
collector.on('collect', async (i) => {
if (i.customId === 'confirm') {

loaEmbed.setColor(0xFF0000);

await message.edit({ embeds: [loaEmbed], components: [] });
} else if (i.customId === 'cancel') {

await message.delete();
}
});
collector.on('collect', async (i) => {
if (i.customId === 'confirm') {

loaEmbed.setColor(0xFF0000);

await message.edit({ embeds: [loaEmbed], components: [] });
} else if (i.customId === 'cancel') {

await message.delete();
}
});
treble/luna
treble/luna7mo ago
replace the message.edit with what i said
JoelHCraft
JoelHCraft7mo ago
Is their not a way of just changing a field rather than making a whole new embed
treble/luna
treble/luna7mo ago
you can construct a builder from the embeds attached from the message Seen you appear to have access to the original builder, you dont need to do this a'd can just edit directly
JoelHCraft
JoelHCraft7mo ago
I cannot be getting this to work for some reason. To be honest you have said ButtonInteraction.update() But that still doesn't explain how to edit a specific embed value
entropy
entropy7mo ago
I believe @polarwolvinny ❄ 🌈 is saying to do something like this:
const newEmbed = new EmbedBuilder(test.embeds[0].toJSON()).setDescription('new description')
buttonInteraction.update({ embeds: [newEmbed] })
const newEmbed = new EmbedBuilder(test.embeds[0].toJSON()).setDescription('new description')
buttonInteraction.update({ embeds: [newEmbed] })
treble/luna
treble/luna7mo ago
yeah but that code is wrong
d.js docs
d.js docs7mo ago
Structures from the API cannot be edited directly. To do so, you can create a new structure (a builder) using the .from() method
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
treble/luna
treble/luna7mo ago
You can just edit it like you would regularly ex call setTitle and it's override
Ashish
Ashish7mo ago
To replace a specific embed field, you can use EmbedBuilder.spliceFields() to change a specific field if you have fields in your embed https://discord.js.org/docs/packages/builders/main/EmbedBuilder:Class#spliceFields
builders | EmbedBuilder
A builder that creates API-compatible JSON data for embeds.