Search code examples
c#.netwpfdiscorddiscord.net

Send a Discord Embed via Webhook C#


I have this code that I want to send to a discord webhook via an embedded message:

var builder = new EmbedBuilder();

builder.WithTitle("Ice Wizard Stats");
builder.AddField("Hit Speed", "1.5sec", true); // True for inline
builder.WithThumbnailUrl("https://i.ibb.co/rc66Lq8/logonew.png");
builder.WithColor(Color.Red);

How am I supposed to send that?


Solution

  • public class dWebHook: IDisposable
        {
            private readonly WebClient dWebClient;
            private static NameValueCollection discord = new NameValueCollection();
            public string WebHook { get; set;}
            public string UserName { get; set; }
            public string ProfilePicture { get; set;}
    
            public dWebHook()
            {
                dWebClient = new WebClient();
            }
    
    
            public void SendMessage(string msgSend)
            {
                discord.Add("username", UserName);
                discord.Add("avatar_url", ProfilePicture);
                discord.Add("content", msgSend);
    
                dWebClient.UploadValues(WebHook, discord);
            }
    
            public void Dispose()
            {
                dWebClient.Dispose();
            }
    

    I think this is what you are looking for