Webrequest to Discord error: Cannot send empty messageSolved
In the past I have used Discord Webhooks with the enqueue procedure and it worked untill recently. I tried the DiscordMessages plugin and failed. I reverted back with the barebones webrequests but still have an issue.
My code is as follows:
public void SendToDiscord(string message)
{
    string payload = "{\"content\":\"" + message + "\"}";
    webrequest.Enqueue(_configuration.DiscordWebhookURL, payload, (code, response) => 
    {
        if (code != 200 && code != 204)
        {
            if (response == null)
            {
                PrintWarning($"Discord didn't respond. Error Code: {code}");
            }
            else
            {
                Puts($"Discord respond with: {response} Payload: {payload}");
            }
        }
    }, this, Core.Libraries.RequestMethod.POST);
}  ​

Error Message in console:

[Update Notice] Discord respond: {"message": "Cannot send an empty message", "code": 50006} Payload: {"content":"Test message from Update Notice by Psystec"}​

My payload is correct and well as my DiscordWebhookURL.
I have created a seperate project to test the Webhook using HttpClient() with the same payload and it worked with no issues.
I do believe the issues is not with the code but with how the webrequst is handled.

Any advice will be appreciated

Kind Regards
Psystec

Did you set header with application/json content type :)

And this is why modding with the Umod Community is such a plesure :) Got it working thanks.
This was my fix for anyone else that that google'd this issue:

public void SendToDiscord(string message)
{
    Dictionary<string, string> headers = new Dictionary<string, string>();
    headers.Add("Content-Type", "application/json");
    string payload = "{\"content\":\"" + message + "\"}";
    webrequest.Enqueue(_configuration.DiscordWebhookURL, payload, (code, response) => 
    {
        if (code != 200 && code != 204)
        {
            if (response == null)
            {
                PrintWarning($"Discord didn't respond. Error Code: {code}");
            }
            else
            {
                Puts($"Discord respond with: {response} Payload: {payload}");
            }
        }
    }, this, Core.Libraries.RequestMethod.POST, headers);
}   
Well there were many threads about it before, so you just did not search enough haha
Might be lol. Its weird how it is only an issue now, used to work without it.
Locked automatically