DiscordEmbeddedSdk 1.0.1
dotnet add package DiscordEmbeddedSdk --version 1.0.1
NuGet\Install-Package DiscordEmbeddedSdk -Version 1.0.1
<PackageReference Include="DiscordEmbeddedSdk" Version="1.0.1" />
<PackageVersion Include="DiscordEmbeddedSdk" Version="1.0.1" />
<PackageReference Include="DiscordEmbeddedSdk" />
paket add DiscordEmbeddedSdk --version 1.0.1
#r "nuget: DiscordEmbeddedSdk, 1.0.1"
#:package DiscordEmbeddedSdk@1.0.1
#addin nuget:?package=DiscordEmbeddedSdk&version=1.0.1
#tool nuget:?package=DiscordEmbeddedSdk&version=1.0.1
<div align="center"> <img alt="DiscordEmbeddedSdk Logo" src="https://raw.githubusercontent.com/ChiaraBm/DiscordEmbeddedSdk/refs/heads/main/Assets/logo.svg" width="120" /> <h1>DiscordEmbeddedSdk</h1> <p><strong>A blazor wrapper for the <a href="https://github.com/discord/embedded-app-sdk">Discord Embedded App SDK</a></strong></p> </div>
A Blazor wrapper around the Discord Embedded App SDK. It handles JavaScript interop so you can build Discord Activities in C# without touching the JS layer directly.
Installation
Register the service in your DI container:
builder.Services.AddDiscordEmbedSdk();
Getting Started
The setup flow follows three steps: initialize the module, subscribe to READY and ERROR, then call ReadyAsync to connect.
var clientId = Configuration.GetValue<string>("Discord:ClientId");
await SdkService.SetupAsync(clientId);
SdkService.OnReady += async ready =>
{
Console.WriteLine($"Connected to {ready.Config.ApiEndpoint}");
// continue setup here
};
SdkService.OnError += async error =>
{
Console.WriteLine($"Error {error.Code}: {error.Message}");
};
await SdkService.SubscribeAsync(DiscordEventType.Ready);
await SdkService.SubscribeAsync(DiscordEventType.Error);
await SdkService.ReadyAsync();
Authorization and Authentication
Inside your OnReady handler, authorize the user to get a code, exchange it for an access token on your backend, then authenticate with the SDK.
SdkService.OnReady += async _ =>
{
var authorizeResult = await SdkService.AuthorizeAsync(clientId, [
"identify",
"guilds",
"rpc.activities.write"
], prompt: "none");
// Exchange the code for an access token on your own backend
var response = await HttpClient.PostAsync("token", new StringContent(authorizeResult.Code));
var accessToken = await response.Content.ReadAsStringAsync();
var authResult = await SdkService.AuthenticateAsync(accessToken);
Console.WriteLine($"Welcome, {authResult.User.Username}");
};
Getting Channel Info
var channelId = await SdkService.GetCurrentChannelAsync();
var channel = await SdkService.GetChannelAsync(channelId);
Console.WriteLine($"Channel: {channel.Name}");
foreach (var state in channel.VoiceStates)
{
Console.WriteLine($"{state.User.Username} - Volume: {state.Volume}");
}
Setting Rich Presence
await SdkService.SetActivityAsync(new Activity
{
Type = 0,
Details = "In the lobby",
State = "Waiting for players",
Assets = new ActivityAssets
{
LargeImage = "my_image_key",
LargeText = "My Game",
SmallImage = "icon_key",
SmallText = "v1.0"
}
});
Subscribing to Events
Subscribe to voice and speaking events by passing a channel ID.
await SdkService.SubscribeSpeakingStartAsync(channelId: channelId);
await SdkService.SubscribeSpeakingStopAsync(channelId: channelId);
await SdkService.SubscribeVoiceStateUpdateAsync(channelId);
SdkService.OnSpeakingStart += async result =>
{
Console.WriteLine($"User {result.UserId} started speaking");
};
SdkService.OnSpeakingStop += async result =>
{
Console.WriteLine($"User {result.UserId} stopped speaking");
};
SdkService.OnVoiceStateUpdate += async result =>
{
Console.WriteLine($"Muted: {result.SelfMute}, Deafened: {result.SelfDeaf}");
};
Other events require no payload:
await SdkService.SubscribeCurrentUserUpdateAsync();
await SdkService.SubscribeActivityInstanceParticipantsUpdateAsync();
SdkService.OnCurrentUserUpdate += async user =>
{
Console.WriteLine($"User updated: {user.Username}");
};
SdkService.OnActivityInstanceParticipantsUpdate += async update =>
{
Console.WriteLine($"Participants: {update.Participants.Count}");
};
Sharing
// Share a link
var result = await SdkService.ShareLinkAsync("Come join my game!", customId: "my_invite");
if (result.Success)
Console.WriteLine("Link shared!");
// Open an external URL
await SdkService.OpenExternalLinkAsync("https://example.com");
Closing the App
await SdkService.CloseAsync(RpcCloseCode.CloseNormal, "Thanks for playing!");
Example Project
A full working example is available in the tests folder. It covers the complete auth flow, retrieving channel and participant data, setting activity, and subscribing to voice events.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. 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. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.