Skip to content

Simple C# written code to send messages embeds and files using discord webhooks

License

Notifications You must be signed in to change notification settings

compujuckel/CSharpDiscordWebhook

 
 

Repository files navigation

CSharpDiscordWebhook

Simple C# written code to send messages embeds and files using discord webhooks

Patreon

If you are using the .NET Framework version, you need to add NewtonSoft.Json to references.

Code usage

Importing webhook code

using Discord;
using Discord.Webhook;

Creating webhook

DiscordWebhook hook = new DiscordWebhook();
hook.Url = "https://discordapp.com/hook-url";

Creating message

DiscordMessage message = new DiscordMessage();
message.Content = "Example message, ping @everyone, <@userid>";
message.TTS = true; //read message to everyone on the channel
message.Username = "Webhook username";
message.AvatarUrl = "http:https://url-of-image";

//embeds
DiscordEmbed embed = new DiscordEmbed();
embed.Title = "Embed title";
embed.Description = "Embed description";
embed.Url = "Embed Url";
embed.Timestamp = DateTime.Now;
embed.Color = Color.Red; //alpha will be ignored, you can use any RGB color
embed.Footer = new EmbedFooter() {Text="Footer Text", IconUrl="http:https://url-of-image"};
embed.Image = new EmbedMedia() {Url="Media URL", Width=150, Height=150}; //valid for thumb and video
embed.Provider = new EmbedProvider() {Name="Provider Name", Url="Provider Url"};
embed.Author = new EmbedAuthor() {Name="Author Name", Url="Author Url", IconUrl="http:https://url-of-image"};

//fields
embed.Fields = new List<EmbedField>();
embed.Fields.Add(new EmbedField() {Name="Field Name", Value="Field Value", InLine=true });
embed.Fields.Add(new EmbedField() {Name="Field Name 2", Value="Field Value 2", InLine=true });

//set embed
message.Embeds = new List<DiscordEmbed>();
message.Embeds.Add(embed);

Sending message

//message
hook.Send(message);

//file
hook.Send(message, new FileInfo("C:/File/Path.file"));

About

Simple C# written code to send messages embeds and files using discord webhooks

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%