user11687745
user11687745

Reputation:

c# - Adding Attachment To Discord Webhook Message

I m trying to add img, .dat file etc. To Discord WebHook Message. ( Local Files ).

Here is my code;

Content Part:

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);

Sending Part:

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;
    }

}

Thanks For Helping !

Upvotes: 0

Views: 1549

Answers (1)

Helyrk
Helyrk

Reputation: 93

WebHook messages don't have attachments, see documentation.

However, there is a file field where you can put your local file, the same way as you do it for messages with attachments or embeds. If you need to send a few files at once, you can include embeds with files in them.

Sadly, I cannot provide the exact code to do that as I'm coding in a different language. But I found a question that seems relevant as it concerns sending local files, and a comment to it points to a documentation article describing how to send an embed with a local file. The author of that question found it helpful.

Upvotes: 2

Related Questions