Discord.Webhook 1.0.9

dotnet add package Discord.Webhook --version 1.0.9
NuGet\Install-Package Discord.Webhook -Version 1.0.9
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Discord.Webhook" Version="1.0.9" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Discord.Webhook --version 1.0.9
#r "nuget: Discord.Webhook, 1.0.9"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install Discord.Webhook as a Cake Addin
#addin nuget:?package=Discord.Webhook&version=1.0.9

// Install Discord.Webhook as a Cake Tool
#tool nuget:?package=Discord.Webhook&version=1.0.9

Discord.Webhook

Used for sending webhook messages to Discord using a Discord Webhook URL - Also completely dependency free!

NuGet version

Samples

Creating a WebhookObject

var webhookObject = new WebhookObject();

Building an embed object

webhookObject.AddEmbed(builder =>
{
	builder.WithTitle("Discord-Webhook lib")
		.WithDescription("Building embed with 'AddEmbed(Action<EmbedBuilder> embedBuilderFunction)'")
		.WithUrl("https://github.com/ToshiroZ/Discord-Webhook")
		.WithThumbnail("https://www.thegatewaypundit.com/wp-content/uploads/trump-mugshot-1.jpg")
		.WithColor(Colors.Magenta)
		.WithImage("https://i.imgur.com/ZGPxFN2.jpg")
		.AddField("New Field", "This is a new field")
		.WithFooter("DiscordUser",
			"https://www.thegatewaypundit.com/wp-content/uploads/trump-mugshot-1.jpg");
});

Sending a message

await new Webhook("my-webhook-url").SendAsync(webhookObject);

Sending a message with an avatar URL and username

await new Webhook("my-webhook-url", "username", "avatar url").SendAsync(webhookObject);

Sending a message to a thread

⚠️ Ensure that your webhook URL is targeting a forum channel, any other channel type will throw an exception!

Since v1.0.9, the library now supports threads, you can set your messages to be targeted to a thread.

await new Webhook("my-webhook-url", "username", "avatar url")
            .SendAsync(webhookObject);

Sending a message even easier

Since v1.0.9, you can send webhook messages easier by using a static method in the Webhook class called SendAsync This method is used to simplify the above call even further, although this is realistically only superior when you're only sending a single webhook message and not multiple calls.

await Webhook.SendAsync("my-webhook-url", webhookObject);

... and you can add an avatar URL, username, etc in the same way as before:

await Webhook.SendAsync("my-webhook-url", webhookObject, "username", "avatar url"); 
await Webhook.SendAsync("my-webhook-url", webhookObject, "username", "avatar url", "thread name");  // For threads

Result

image

Error handling

Since v1.0.9, the library now handles exceptions from Discord's API to allow for easier debugging and handling on an application-level. All exceptions thrown by Discord are handled with a DiscordWebhookException in the Discord.Webhook.Exceptions namespace. You can handle exceptions like this:

try 
{
            var webhookObject = new WebhookObject();
            webhookObject.AddEmbed(builder =>
            {
            	builder.WithTitle("Discord-Webhook lib")
            		.WithDescription("Building embed with 'AddEmbed(Action<EmbedBuilder> embedBuilderFunction)'")
            		.WithUrl("https://github.com/ToshiroZ/Discord-Webhook")
            		.WithThumbnail("https://www.thegatewaypundit.com/wp-content/uploads/trump-mugshot-1.jpg")
            		.WithColor(Colors.Magenta)
            		.WithImage("https://i.imgur.com/ZGPxFN2.jpg")
            		.AddField("New Field", "This is a new field")
            		.WithFooter("DiscordUser",
            			"https://www.thegatewaypundit.com/wp-content/uploads/trump-mugshot-1.jpg");
            });
            
            await new Webhook("my-webhook-url").SendAsync(webhookObject);
}
catch (DiscordWebhookException ex)
{
            Console.WriteLine($"Exception from Discord: {ex.Message}");
}
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Discord.Webhook:

Package Downloads
Serilog.Sinks.Discord.Lite

This client library uses a lightweight discord webhook library to send logs to a Discord Channel. It presents a nice format to see complete information about Errors and Exceptions. Removes other dependencies from Discord.Net causing compatibility issues with EF

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.9 1,358 8/26/2023
1.0.8 2,777 4/19/2021
1.0.7 66,962 3/13/2021
1.0.6 328 3/12/2021
1.0.5 337 3/12/2021
1.0.4 409 3/2/2021
1.0.3 312 3/1/2021
1.0.2 993 2/5/2020
1.0.1 512 2/4/2020
1.0.0 451 2/4/2020