discord-webhook-client
4.0.0
dotnet add package discord-webhook-client --version 4.0.0
NuGet\Install-Package discord-webhook-client -Version 4.0.0
<PackageReference Include="discord-webhook-client" Version="4.0.0" />
<PackageVersion Include="discord-webhook-client" Version="4.0.0" />
<PackageReference Include="discord-webhook-client" />
paket add discord-webhook-client --version 4.0.0
#r "nuget: discord-webhook-client, 4.0.0"
#addin nuget:?package=discord-webhook-client&version=4.0.0
#tool nuget:?package=discord-webhook-client&version=4.0.0
Discord Webhook Client
Simple .NET client to send Discord (https://discordapp.com/) messages using a webhook.
Reference documentation for creating this client: Discord Webhooks Guide and Discord Developer Portal.
Target
.NET 8.0+
For more information about suported versions visit https://docs.microsoft.com/pt-br/dotnet/standard/net-standard
Installation
NuGet
Install-Package discord-webhook-client
.NET CLI
dotnet add package discord-webhook-client
How to send a message?
Sending a message is very simple!
- Add reference to namespace
JNogueira.Discord.WebhookClient
- In the Program.cs file add
service.AddDiscordWebhookClient("Your Discord webhook URL here!")
- Get an instance of the class
DiscordWebhookClient
. For more information about how to create a Discord webhook, visit https://support.discordapp.com/hc/en-us/articles/228383668-Intro-to-Webhooks - Create your
DiscordMessage
instance with all parameters of your message. - Call
DiscordWebhookClient.SendToDiscordAsync
method to send your message to Discord!
// Add reference to namespace JNogueira.Discord.Webhook.Client
using JNogueira.Discord.WebhookClient;
service.AddDiscordWebhookClient("Your Discord webhook URL where!");
// Get an instance of DiscordWebhookClient
var discordClient = serviceProvider.GetService<DiscordWebhookClient>();
// Create your DiscordMessage with all parameters of your message.
var message = new DiscordMessage(
"Discord Webhook Client sent this message! " + DiscordEmoji.Grinning,
username: "Username",
avatarUrl: "https://avatars3.githubusercontent.com/u/24236993?s=460&v=4",
tts: false,
embeds: new[]
{
new DiscordMessageEmbed(
"Embed title " + DiscordEmoji.Thumbsup,
color: 0,
author: new DiscordMessageEmbedAuthor("Embed 1 author name"),
url: "https://github.com/jlnpinheiro/discord-webhook-client/",
description: "This is a embed description.",
fields: new[]
{
new DiscordMessageEmbedField("Field 1 name", "Field 1 value"),
new DiscordMessageEmbedField("Field 2 name", "Field 2 value")
},
thumbnail: new DiscordMessageEmbedThumbnail("https://avatars3.githubusercontent.com/u/24236993?s=460&v=4"),
image: new DiscordMessageEmbedImage("https://avatars3.githubusercontent.com/u/24236993?s=460&v=4"),
footer: new DiscordMessageEmbedFooter("This is a embed footer text", "https://avatars3.githubusercontent.com/u/24236993?s=460&v=4")
)
}
);
// Send the message!
await discordClient.SendToDiscord(message);
Look at to your Discord channel...your message is there!
Sending a message with file attachments
var message = new DiscordMessage(
...
);
var file1 = new DiscordFile("test1.txt", Encoding.UTF8.GetBytes("This is the first file."));
var file2 = new DiscordFile("test2.txt", Encoding.UTF8.GetBytes("This is the secound file."));
await client.SendToDiscord(message, new[] { file1, file2 });
Send message as file attachment on exception
When an exception is throwing on sending the message, a new message can be sent to Discord with attachments containing message data and exception information.
var message = new DiscordMessage(
content: new string('0', 7000), // <-- The content length limit is 2000 characters => Exception is throwing.
...
);
await _client.SendToDiscord(message, true);
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- Microsoft.AspNet.WebApi.Client (>= 6.0.0)
- Microsoft.Extensions.Configuration.Abstractions (>= 9.0.6)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.6)
- Microsoft.Extensions.Http (>= 9.0.6)
- NotifiqueMe (>= 3.1.0)
- Polly (>= 8.6.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on discord-webhook-client:
Package | Downloads |
---|---|
logger-discord-provider
A .NET Core Logger provider to send log messages to Discord. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Bug fix and Discord field limits validations.