【问题标题】:c# - Adding Attachment To Discord Webhook Messagec# - 添加附件到 Discord Webhook 消息
【发布时间】:2020-07-27 12:30:54
【问题描述】:

我正在尝试将 img、.dat 文件等添加到 Discord WebHook 消息。 (本地文件)。

这是我的代码;

内容部分:

string url = "webhook"
string mesaj "example";

 NameValueCollection message = new NameValueCollection()  {
                    { "username", "Beko BOT" },
                    { "avatar_url", "https://i.ibb.co/qrcrHP4/B-Kare.png"},
                    { "content", mesaj }
                };

                Http.Post(url, message);

发送部分:

public class Http
{
    public static byte[] Post(string uri, NameValueCollection pairs)
    {
        byte[] numArray;
        using (WebClient webClient = new WebClient())
        {
            numArray = webClient.UploadValues(uri, pairs);
        }
        return numArray;
    }

}

感谢您的帮助!

【问题讨论】:

    标签: c# file discord embed attachment


    【解决方案1】:

    WebHook 消息没有附件,请参阅documentation。

    但是,有一个 file 字段,您可以在其中放置本地文件,就像放置带有附件或嵌入的邮件一样。如果您需要一次发送几个文件,您可以在其中包含嵌入文件。

    遗憾的是,我无法提供确切的代码来执行此操作,因为我正在使用不同的语言进行编码。但我发现question 似乎与发送本地文件有关,并且对它的评论指向documentation article,描述如何发送带有本地文件的嵌入。该问题的作者发现它很有帮助。

    【讨论】:

      猜你喜欢
      • 2022-06-12
      • 2020-03-20
      • 2020-07-27
      • 2021-07-15
      • 2019-03-05
      • 2017-09-12
      • 2012-12-03
      • 2021-03-11
      • 2021-10-29
      相关资源
      最近更新 更多