Webhook (Message)

Voici comment créer un webhook :

  • Avec ModKit :

public static DiscordWebhookClient WebhookClient = new DiscordWebhookClient("url_webhook");

await DiscordHelper.SendMsg(DiscordPlugin.WebhookClient, $"Votre message");

  • Sans ModKit :

private static readonly HttpClient client = new HttpClient();

public static async Task SendWebhook(string message, string url)
{
    try
    {
        var payload = new
        {
            content = message
        };

        string json = JsonConvert.SerializeObject(payload);
        StringContent data = new StringContent(json, Encoding.UTF8, "application/json");

        HttpResponseMessage response = await client.PostAsync(url, data);

        if (!response.IsSuccessStatusCode)
        {
                UnityEngine.Debug.LogError($"Erreur Webhook : {response.StatusCode} - {response.ReasonPhrase}");
        }
    }
    catch (Exception ex)
    {
        UnityEngine.Debug.LogError("Erreur lors de l'envoi du webhook : " + ex.Message);
    }
}

Mis Ă  jour