Skip to content

Instantly share code, notes, and snippets.

@pixelnerve
Forked from lot224/discordWebHook.cs
Created May 13, 2024 11:28
Show Gist options
  • Save pixelnerve/ece04ced0b1527c145502b3aa7526bba to your computer and use it in GitHub Desktop.
Save pixelnerve/ece04ced0b1527c145502b3aa7526bba to your computer and use it in GitHub Desktop.
An very basic example of a Webhook in C# to Discord.
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
namespace discordWebHook
{
class Program
{
private static HttpClient client;
public static HttpClient Client {
get {
if (client == null)
client = new HttpClient();
return client;
}
}
static void Main(string[] args)
{
//https://discordapp.com/api/webhooks/123456789012345678/ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEF
var WebHookId = "123456789012345678";
var WebHookToken = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyzABCDEF";
const string Success = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0041_large.png?v=1369543932";
const string Cloud = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0189_large.png?v=1369544011";
const string Failure = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0035_large.png?v=1369543848";
const string Meh = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0052_large.png?v=1369543755";
const string Warning = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0016_large.png?v=1369543588";
const string colorBlue = "1F61E6";
const string colorGreen = "80E61F";
const string colorRed = "E7421F";
const string colorPurple = "C61FE6";
const string colorYellow = "E6C71F";
var SuccessWebHook = new
{
username = "Text of the message",
content = "This is the main content section",
avatar_url = "https://cdn.shopify.com/s/files/1/0185/5092/products/persons-0041_large.png?v=1369543932",
embeds = new List<object>
{
new
{
title = "Embed",
url="https://www.google.com/search?q=something",
description="This is the description section of the Embed, the embed has a color bar to the left side",
color= int.Parse(colorGreen, System.Globalization.NumberStyles.HexNumber)
},
new
{
title = "Another Embed",
url="https://www.google.com/search?q=somethingElse",
description="This is the description section of the Embed, the embed has a color bar to the left side",
color= int.Parse(colorPurple, System.Globalization.NumberStyles.HexNumber)
}
}
};
string EndPoint = string.Format("https://discordapp.com/api/webhooks/{0}/{1}", WebHookId, WebHookToken);
var content = new StringContent(JsonConvert.SerializeObject(SuccessWebHook), Encoding.UTF8, "application/json");
Client.PostAsync(EndPoint, content).Wait();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment