Send a Discord Embed via Webhook C#

时间秒杀一切 提交于 2020-07-22 08:07:41

问题


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?


回答1:


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



来源:https://stackoverflow.com/questions/59398782/send-a-discord-embed-via-webhook-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!