My Discord bot can get a png image from my database and store it as a byte array. How would I embed this image onto Discord's Rich Embed using the c# Discord.Net library?
CodePudding user response:
I noticed that SendFileAsync
has two constructors for a string file name and Stream respectively. A google search about Streams and byte arrays led me to here. Then I looked more into Discord.Net's EmbedBuilder Class and found information about embedding a local image file in the rich embed
Using those resources I wrote this and the image was displayed correctly
using (System.IO.MemoryStream imgStream = new System.IO.MemoryStream(byteArrayImage))
{
build.WithThumbnailUrl("attachment://anyImageName.png"); //or build.WithImageUrl("")
await Context.Channel.SendFileAsync(imgStream, "anyImageName.png", "", false, build.Build());
}