Table of Contents

Class DSharpPlusBridge

Namespace
Nyra.DSharpPlus
Assembly
Nyra.DSharpPlus.dll

Wraps a DSharpPlus.DiscordClient or DSharpPlus.DiscordShardedClient for Nyra, forwards the voice events of the current user and sends the raw gateway voice state update.

public sealed class DSharpPlusBridge : IDiscordBridge, IGuildRemovalSource, IDisposable
Inheritance
DSharpPlusBridge
Implements
Inherited Members

Constructors

DSharpPlusBridge(DiscordClient, int?)

Wraps a single DSharpPlus.DiscordClient.

public DSharpPlusBridge(DiscordClient client, int? shardCount = null)

Parameters

client DiscordClient

The client to wrap.

shardCount int?

The shard count the gateway routes by. Pass it when the client is one shard of a sharded setup so the bridge can reject guilds of another shard, null skips the rejection.

Remarks

DSharpPlus.DiscordClient.ShardCount reports the configured count before the first connect, then the count Discord recommends once connected, never the count the gateway routes by.

DSharpPlusBridge(DiscordShardedClient)

Wraps a sharded client, one bridge for the voice events of every shard.

public DSharpPlusBridge(DiscordShardedClient client)

Parameters

client DiscordShardedClient

The sharded client to wrap.

Properties

Logger

The bridge's logger, or null when neither the library nor the caller provides one.

public ILogger? Logger { get; }

Property Value

ILogger

Methods

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

SendVoiceUpdateAsync(ulong, ulong?, bool, bool, CancellationToken)

Sends the gateway voice state update (op 4), a channel id joins it, a null channel id leaves the voice channel again.

public Task SendVoiceUpdateAsync(ulong guildId, ulong? channelId, bool selfDeaf = false, bool selfMute = false, CancellationToken cancellationToken = default)

Parameters

guildId ulong

The guild to send the voice state update in.

channelId ulong?

The voice channel to join, null leaves the voice channel.

selfDeaf bool

Whether the update deafens the current user. The flags apply to joins. A leave may drop them where the library's disconnect route fixes its own (Discord.Net), the core's leaves carry the defaults and its rescue re-join replays the flags the gateway last confirmed.

selfMute bool

Whether the update mutes the current user. Like selfDeaf, joins carry it, a leave may drop it, the leaves carry the defaults and the rescue re-join replays the observed flags.

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task

A task that completes when the update was sent, or when the library dropped it (DSharpPlus during a gateway reconnect).

Remarks

Implementations must honor the cancellation token as far as the underlying library allows, a send the library cannot cancel is abandoned alive, its late join parks the bot in a channel it has no player for, and the handshake's timeout guards it.

An implementation whose library exposes no raw op-4 send resolves the join and the leave through the library's own audio state instead, so channel resolution and the library's audio locks apply to both.

WaitForReadyAsync(CancellationToken)

Returns the client's identification once it is available, completing immediately when it already is.

public Task<ClientInformation> WaitForReadyAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to cancel the operation.

Returns

Task<ClientInformation>

The client's identification, once it is available. The first completion is what the node keeps for its connection's lifetime, a bridge whose identity changes mid-flight keeps reporting the first one.

Remarks

The DSharpPlus and Discord.Net built-ins resolve it from the REST login, where the gateway may still be connecting (a bridge's sends are guarded on socket-up separately), NetCord waits for the gateway's READY or RESUME. The extension bounds its own wait at sixty seconds, a gateway that never becomes ready surfaces as a TimeoutException from ConnectAllNodesAsync(CancellationToken), a NetCord gateway that closed fatally (a bad token and friends) fails the wait fast instead and the close surfaces as the bridge's InvalidOperationException from the same call.

Implementations must remember the first completion, later calls complete synchronously with the same identification, even when the gateway has dropped again in between, the node's own wait carries no bound of its own.

Implementations must fail pending waits on dispose (TaskCanceledException), a wait left pending would hang the unbounded node wait after it.

Events

GuildRemoved

Raised when the bot was removed from a guild.

public event EventHandler<GuildRemovedEventArgs>? GuildRemoved

Event Type

EventHandler<GuildRemovedEventArgs>

Remarks

Not raised for guild outages.

VoiceServerUpdated

Raised when Discord allocates or re-targets the voice server of a guild.

public event EventHandler<VoiceServerUpdatedEventArgs>? VoiceServerUpdated

Event Type

EventHandler<VoiceServerUpdatedEventArgs>

VoiceStateUpdated

Raised when the voice state of the current user changes in a guild.

public event EventHandler<VoiceStateUpdatedEventArgs>? VoiceStateUpdated

Event Type

EventHandler<VoiceStateUpdatedEventArgs>