Skip to content

[Bug]: Editting an embed with an attachment duplicates the image outside of the embed message #2236

@defunky

Description

@defunky

Check The Docs

  • I double checked the docs and couldn't find any useful information.

Verify Issue Source

  • I verified the issue was caused by Discord.Net.

Check your intents

  • I double checked that I have the required intents.

Description

When an embed has image attached and you try to modify the embed, it will cause the image to be attached to regular message outside of the embed alongside the image within the embed itself. You can get around this by nullifying the attachment as part of the ModifyAsync however this will cause the image within the embed to become a deadlink after a period of time as discord will delete the image off its server.

Version

3.5.0

Working Version

No response

Logs

N/A

Sample

// Create the original message and attach an image to the embed
var embed = new EmbedBuilder()
                    .WithTitle("Test")
                    .WithDescription("Description")
                    .WithImageUrl($"attachment://{fileName}")
                    .WithColor(Color.LightGrey);
await Context.Channel.SendFileAsync(stream, fileName, embed: embed.Build())
// Modify the message by grabbing the embed and generate a embedbuilder
var message = Context.Interaction as SocketMessageComponent;
var embed = message.Message.Embeds.First().ToEmbedBuilder();

// Simply edit the description, you don't even need to modify ImageUrl
embed.WithDescription("New description");
await message.Message.ModifyAsync(x => 
    {
        // Uncommenting the line below will prevent the image being duplicated but will kill the link to image after couple of mins
        // x.Attachments = new Optional<IEnumerable<FileAttachment>(Enumerable.Empty<FileAttachment>());
        x.Embed = embed.Build()
    });


Packages

N/A

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions