#Embed attachment:// scheme not working as expected

1 messages · Page 1 of 1 (latest)

cedar sun
#

My bot is sending an embed which should have an image in it.
Previously, i added the file to the messagebuilder with .WithFile and used the attachment:// scheme to access it in the embed.
It used to work; the file was not shown as attachment of the message but embedded in the embed.

Since about one week (i haven't made any changes to my code), the file is embedded in the message (outside the embed), and the embed has no image.
I updated D#+ and adapted the code to use AddFile, so it's like this now:

 response.AddFile(File.OpenRead(path));
embed.ImageUrl = "attachment://" + Path.GetFileName(path);

However that didn't fix the embed.
Am i missing something?

rich herald
#

AddFile will try to use the filename from the filestream, however there is a chance that it won't match the uploaded filename because of restrictions to the filenames discord allows. in that case, the code above will not provide the correct name to the attachment:// url. instead, try passing a filename explicitly to AddFile and use that with the url as well

cedar sun
#

Thanks, that fixed it!

Another related question:
The message has buttons on it, which i disable after an Interactivity Result timed out.
For that, i just clear the components of the original messagebuilder ("response") and add new components, and re-build the embed and assign it again to the messagebuilder.
Then, i use sentMessage.ModifyAsync(response) to update the message.

When i do this, the embedded image disappears.
How should that be handled?

here's the link to the relevant code, but disclaimer - its a complete mess: https://github.com/toobeeh/Palantir/blob/master/Commands/MiscCommands.cs#L242

rich herald
#

that... sounds weird. i could imagine that the edit removes the attachment (for whatever reason) but since you reuse the builder i have no idea why it would do that. or maybe editing breaks the attachment:// in general?

#

frankly, if you can, and that's a fixed image, i would just make sure it's hosted somewhere online and included in the embed with a regular URL

cedar sun
#

Hmm okay, at least now i know that its not just a stupid error on my side.
Thanks for the help :)