Table of Contents

Interface IDiscordBridge

Namespace
Nyra.Abstractions
Assembly
Nyra.dll

The Discord client contract Nyra runs on, implemented once per Discord library.

public interface IDiscordBridge

Remarks

Voice events are only raised for the current user, the implementation filters other users out.

Properties

Logger

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

ILogger? Logger { get; }

Property Value

ILogger

Methods

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.

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.

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

VoiceServerUpdated

Raised when Discord sends a complete voice server update for a guild, the allocation a join handshake waits on, or the re-targeting of a live connection's server (move or failover).

event EventHandler<VoiceServerUpdatedEventArgs>? VoiceServerUpdated

Event Type

EventHandler<VoiceServerUpdatedEventArgs>

Remarks

The sender must be the subscribed bridge instance itself, consumers key echo state by that instance, and a forwarding implementation that raises with another bridge as the sender (the exact trap NetCord's bridge re-raises with this to avoid) silently breaks the echo tracking.

VoiceStateUpdated

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

event EventHandler<VoiceStateUpdatedEventArgs>? VoiceStateUpdated

Event Type

EventHandler<VoiceStateUpdatedEventArgs>

Remarks

The sender rule of VoiceServerUpdated applies here too.