【问题标题】:Display byte array image onto Discord Rich Embed在 Discord Rich Embed 上显示字节数组图像
【发布时间】:2021-09-11 15:27:12
【问题描述】:

我的 Discord 机器人可以从我的数据库中获取 png 图像并将其存储为字节数组。如何使用 c# Discord.Net 库将此图像嵌入到 Discord 的 Rich Embed 中?

【问题讨论】:

    标签: c# image discord.net


    【解决方案1】:

    我注意到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());
    } 
    

    【讨论】:

      猜你喜欢
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      • 2021-11-17
      • 2017-01-13
      • 1970-01-01
      • 1970-01-01
      • 2013-07-24
      • 2021-11-01
      相关资源
      最近更新 更多