📖
Wiki Nova Life
  • Bienvenue !
  • Discord MOD
  • Serveur
    • Introduction
    • L'hébergeur
    • La configuration
    • Ajouter des plugins
  • Plugins
    • Introduction
    • Informations pour débuter
    • Aides
      • ModKit
      • Base d'un plugin
      • CenterText
      • Config JSON
      • Commande
      • Cooldown individuel
      • Cooldown global
      • Événements
      • Points
      • Panels
      • Webhook (Embed)
      • Webhook (Message)
  • Flocages
    • Introduction
    • Informations pour débuter
    • Flocage de vêtement
    • Flocage de véhicule
    • Flocage de panneau
Propulsé par GitBook
Sur cette page
  1. Plugins
  2. Aides

Webhook (Embed)

Voici le code pour envoyer un webhook sous forme d'embed :

private static readonly HttpClient httpClient = new HttpClient();

private async Task SendWebhook(string url, string title, params (string Name, string Value, bool Inline)[] fields)
{
    try
    {
        var embed = new
        {
            title,
            color = 0xff0000,
            timestamp = DateTime.UtcNow.ToString("o"),
            fields = fields.Select(f => new { name = f.Name, value = f.Value, inline = f.Inline }).ToArray()
        };

        var payload = new { embeds = new[] { embed } };
        string json = JsonConvert.SerializeObject(payload, Formatting.Indented);

        using (var request = new HttpRequestMessage(HttpMethod.Post, url))
        {
            request.Content = new StringContent(json, Encoding.UTF8, "application/json");
            request.Headers.Add("User-Agent", "UnityWebhookClient");

            HttpResponseMessage response = await httpClient.SendAsync(request);
            if (!response.IsSuccessStatusCode)
            {
                Debug.LogError($"[Webhook Error] Code: {response.StatusCode}, Message: {await response.Content.ReadAsStringAsync()}");
            }
        }
    }
    catch (Exception ex)
    {
        Debug.LogError($"[Webhook Error] Exception : {ex.Message}");
    }
}

// Exemple d'utilisation : 
public async override void OnPlayerMoney(Player player, double amount, string reason)
{
    base.OnPlayerMoney(player, amount, reason);
    string title = "💰 Nouvelle Transaction";
    var fields = new[]
    {
        ("Heure", DateTime.Now.ToString("HH:mm:ss"), true),
        ("Joueur", $"{player.FullName}", true),
        ("ID", $"{player.character.Id}", true),
        ("Steam ID", $"{player.account.steamId}", true),
        ("Montant", $"{amount}€", true),
        ("Raison", reason, false) // "False" désigne si la valeur doit être alignée aux autres
    };
    await SendWebhook("webhook_url", title, fields);
}
PrécédentPanelsSuivantWebhook (Message)

Dernière mise à jour il y a 3 mois