Imagine getting critical alerts from your .NET application delivered straight to your Discord server…
Email might be too slow. Slack may not be part of your stack. But if your team is already active on Discord, why not turn it into your centralized alert hub?
In this guide, you’ll learn how to send important system notifications from your .NET applications straight into a Discord channel using webhooks.
Setting Up a Discord Webhook
Before your .NET application can send messages to Discord, you need to set up a Webhook URL. This URL acts as an entry point for your system to post notifications directly into a Discord channel.
Follow these steps:
1 – Create or Choose a Channel
In your Discord server, create a dedicated channel for alerts (e.g., #notes-log).
Keeping alerts in a separate channel avoids clutter and makes them easier to track.
2 – Open Channel Settings
Click the gear icon next to the channel name.
Navigate to Integrations → Webhooks.
3 – Create a New Webhook
Click New Webhook.
Give it a descriptive name, such as “Notes – Log”
Optionally, set an avatar to visually distinguish alerts.
4 – Copy the Webhook URL
Click Copy Webhook URL and store it securely.
This URL is essentially your “password” to post messages into the channel, don’t share it publicly.
At this point, you have everything you need to start sending notifications from your .NET application
Preparing Your .NET Project
Before sending notifications to Discord, we need to set up our .NET project with the right structure, dependencies, and configuration to handle webhooks reliably. In this example, we’ll use the Discord.Net library, which provides a DiscordWebhookClient for sending messages and embeds to a channel.
Run the following command in your project:
PowerShell
dotnet add package Discord.Net
dotnet add package Discord.Net.WebhookThese packages give us access to Discord’s webhook client and strongly-typed configuration options in .NET.
Add your Discord Webhook URL to appsettings.json, aws secrets, environment variables, etc:
JSON
"Discord": {
"NotesLogWebhook": "https://discord.com/api/webhooks/XXXXXXXXXX/YYYYYYYYYY"
} Create a options class
C#
public class DiscordOptions
{
public string? NotesLogWebhook { get; set; }
} Then bind it in Program.cs:
C#
builder.Services.Configure<DiscordOptions>(
builder.Configuration.GetSection("Discord")); Implement the notifier service:
C#
public sealed class DiscordLogNotifier(IOptions<DiscordOptions> options) : IDiscordNotifier
{
public async Task SendNoteCreatedAsync(Note note, CancellationToken ct = default)
{
var client = new DiscordWebhookClient(options.Value.NotesLogWebhook);
var embed = new EmbedBuilder()
.WithTitle("Note Created")
.WithDescription($"A note was created with ID **{note.Id}**.")
.WithColor(Color.Green)
.WithTimestamp(DateTimeOffset.UtcNow)
.AddField("Description",
string.IsNullOrWhiteSpace(note.Description) ?
"(empty)" :
note.Description, false)
.Build();
await client.SendMessageAsync(
text: "New Note",
embeds: new[] { embed },
options: new RequestOptions { CancelToken = ct });
}
} Embed Styling: We use Discord’s EmbedBuilder to create visually clear alerts.
Fail-Safe: If the webhook URL is missing, the method exits gracefully.
With this setup, your application is now ready to send structured, real-time notifications to your Discord channel whenever a Note is created.
Testing the Discord Notifier with a Minimal API Endpoint
Now that our DiscordLogNotifier is implemented, let’s trigger it from a Minimal API endpoint.
Below is an example POST /notes endpoint that creates a new note, saves it to the database, and sends a notification to Discord:
C#
app.MapPost("notes", async (
[FromBody] CreateNoteRequest request,
AppDbContext context,
IDiscordNotifier discord,
CancellationToken ct) =>
{
if (string.IsNullOrWhiteSpace(request.Description))
{
return Results.BadRequest();
}
var note = new Note
{
Description = request.Description,
};
await context.AddAsync(note, ct);
await context.SaveChangesAsync(ct);
await discord.SendNoteCreatedAsync(note, ct);
return Results.Ok(note);
});If everything is set up correctly, you’ll see the new note in your database and a rich embed in your Discord channel within seconds:
You can adapt the embed color depending on the nature of the notification:
C#
.WithColor(Color.Red)
//or
.WithColor(new Color(255, 165, 0)) Pretty simple, right? Quick and practical too.
Conclusion
Integrating Discord into your .NET applications for system notifications is a simple yet powerful way to keep your team informed in real time.
This approach works just as well for feature deployments, background job statuses, performance warnings, or critical errors.
And because it’s built directly into your application, you maintain full control over when, how, and what gets sent.
Start small, send alerts for key events, and expand as you identify more scenarios where instant visibility can save time, reduce downtime, and keep your system healthy.