#Removing Attachments With UpdateAsync?

1 messages · Page 1 of 1 (latest)

upbeat anvil
#

Idea: use UpdateAsync() to remove an embed from a message.
Here's my code that sends the attachment:

await interaction.UpdateAsync(x =>
            {
                x.Embed = null;
                x.Attachments = new[] { new FileAttachment(path: "VerdantRecords.png", fileName: "VerdantRecords.png") };
                x.Components = // Other working stuff

And here's the code that removes the attachment:

await interaction.UpdateAsync(x =>
            {
                x.Embed = // Other working stuff
                x.Attachments = null;
                x.Components = // Other working stuff
            });

The attachment is sent just fine, but when setting x.Attachments to null, it... times out? Errors? Unsure. I tried using a try and catch statement, but there's no thrown exception.

Am I doing something wrong? Am I crazy? Usually setting the Embed, Content, etc., to null works perfectly. I have tried using ModifyOriginalResponseAync as well.

unique cargo
#

what if you set that to an empty array?

#

dnet's modify methods are just inconsistent

#

we should probably review all of those in v4

#

so they'd work as expected...

upbeat anvil
unique cargo
upbeat anvil
#

Side note: updating to another image works just fine Shrug

upbeat anvil
#

For anyone that stumbles upon this thread, this was mostly fixed in D.NET 3.12.0. In a nutshell, you currently need to use ModifyAsync(), as UpdateAsync() and ModifyOriginalResponseAsync() don't seem to work here.
GitHub Issue: https://github.com/discord-net/Discord.Net/pull/2742
Working code:

await Context.Interaction.DeferAsync(true);

var interaction = await Context.Interaction.GetOriginalResponseAsync();

await interaction.ModifyAsync(x =>
{
    x.Attachments = null;
    x.Embed = // Stuff
    x.Components = // Stuff
});
GitHub

PR in relation to #2236
Edits Permitted
Simple fix, could be improved if necessary. ModifyAsync can now has access to an Attachment object if an empty array is passed the image(s) will be removed f...