#[SOLVED] Sending an image that embeds?

1 messages · Page 1 of 1 (latest)

astral creek
#

Hello, I'm sending an image using

new DiscordMessageBuilder().WithFile(fileStream);

The image is being sent as a file, but it won't embed/render.
How can I solve this?
PS: I've tried with sending a .png image, got the same result.

#

I've looked at the documentation and saw the Embed Image, but it requires an URL, I can't really upload images, because the software I'm contributing to is used by a lot of people and we don't have any funds to finance an API.

#

It would be ideal if we could have the image embed if sent as a file.

vital jetty
#

use the url "attachment://<uploadFileNAme>" in .WithImage

vital jetty
#

no not that one

astral creek
#

I do not see any other

vital jetty
#

you still need the MessageBuilder with the .WithFile

#

just use the AddEmbed on that with that EmbedBuilder

#

the part after the attachment:// is the files name not its full path

astral creek
#

Let me try

vital jetty
#

that is the problem

astral creek
#

still empty

#

Tried with the windows strings that have \ and got the same result

vital jetty
#

just

#

remove the part before the /

astral creek
#

before the /Map ?

vital jetty
#

Rendered_Maps/ < this

astral creek
#

still doesn't work

#

Any ideas?

vital jetty
#

dont put the attachment:// to the file

#

only to the embed image

astral creek
vital jetty
#

also I doubt embeds support .bmp

astral creek
#

I tried with png too

vital jetty
#

youre missing the embed

#

you use both the embed and the messagebuilder

#

not one or the other

astral creek
#

Something like this?

#

I get an empty embed

#

Tried with .WithFiles too doesn't work

#

Could you please write out the code part, I just picked up this library, I know it's spoon feeding but I tried different combinations already?

#

Thanks

vital jetty
#

cant give the exact code example but heres a step by step tutorial

  • do not send the embed, just store it in a variable
  • get the commented .SendMessageAsync call from a few lines below, and just add .AddEmbed(theVariableYouPutTheEmbedBuilderIn) call there
  • send the MessageBuilder, not the EmbedBuilder
astral creek
#

So basically this? :

var embed = new DiscordEmbedBuilder().WithImageUrl($"attachment://{filePath}");
var messageBuilder = new DiscordMessageBuilder().AddEmbed(embed);
_client.SendMessageAsync(_channel, messageBuilder).Wait();
vital jetty
#

you deleted .AddFile

astral creek
#

I've added WithFile

vital jetty
#

oh yeah that

astral creek
#
var embed = new DiscordEmbedBuilder().WithImageUrl($"attachment://{filePath}");
var messageBuilder = new DiscordMessageBuilder()
.AddEmbed(embed)
.WithFiles(new Dictionary<string, Stream>() { { filePath, fs } });
_client.SendMessageAsync(_channel, messageBuilder).Wait();
vital jetty
#

that should do it

astral creek
#

doesn't work either way

vital jetty
#

could it be that the image is corrupted and the client cannot display it

astral creek
#

I'll make an image using paint

#

to test it out

hallow hare
#

you're also giving discord a file path, not a file name

astral creek
hallow hare
#

then rename your variable please

astral creek
#

I strip evertything before the file name

hallow hare
#

so filePath contains the string "file.png" or similar?

astral creek
#

The images are "corrupted"

#

🗿 🗿 🗿

#

seems that they're not properly converted

#

but the .net paint does not have issues with them

#

this one works

#

Anyone knows a good image converting library for all platforms in .NET Core?

#

Btw thanks for the help

vital jetty
#

skiasharp for drawing

astral creek
#

Slapped an example from their documentation, I think I am doing it correctly

hallow hare
#

ehm… maybe im just having a moment… but this code looks wrong

#

like it doesnt save the image

#

it just renames the .bmp to .png

astral creek
#

I think that it should save into the opened file

#

maybe I am wrong

hallow hare
#

if you just need the image to upload it to discord you dont need to save it to disk

#

you can pass the meory stream to .WithFile

astral creek
#

I have the render in the console, and as an image, I use .bmp because it's the only one that works on all platforms in .NET

hallow hare
#

how large are these maps? (in pixels)

#

or images rather

astral creek
#

depends on the scaling factor

#

the smallest one is like 128x128

hallow hare
#

and how big can they get? because if you want to convert them to png later on you can just leave them in memory… but depending on your hardware and how often the function is called that could also end badly (50 images each 50mb in memory, possible, but could also crash the bot on resource constrained hardware)

#

well, the crashing part probably depends on your error handling but i think you get the point

astral creek
#

they can't get that bigger

#

I think max is 1024

#

let me check if we have a limit on the picture size

#

they're usually in kilobytes

hallow hare
#

ok, so if you dont need the .bmp image FILE, just write it in a memory stream and pass that to image magickk to write in a png file

astral creek
#

Got it working, thanks for the help.

#

❤️