【发布时间】:2021-09-11 15:27:12
【问题描述】:
我的 Discord 机器人可以从我的数据库中获取 png 图像并将其存储为字节数组。如何使用 c# Discord.Net 库将此图像嵌入到 Discord 的 Rich Embed 中?
【问题讨论】:
标签: c# image discord.net
我的 Discord 机器人可以从我的数据库中获取 png 图像并将其存储为字节数组。如何使用 c# Discord.Net 库将此图像嵌入到 Discord 的 Rich Embed 中?
【问题讨论】:
标签: c# image discord.net
我注意到SendFileAsync 有两个分别用于字符串文件名和 Stream 的构造函数。关于流和字节数组的谷歌搜索将我带到here。然后我更深入地研究了 Discord.Net 的 EmbedBuilder 类,找到了关于embedding a local image file in the rich embed的信息
使用我写的这些资源,图像正确显示
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());
}
【讨论】: