Table of Contents

Class NetCordBridge

Namespace
Nyra.NetCord
Assembly
Nyra.NetCord.dll

Wraps a NetCord.Gateway.GatewayClient or NetCord.Gateway.ShardedGatewayClient for Nyra.

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

Remarks

NetCord logs through its own IGatewayLogger, configured only at client creation and not exposed afterwards, so the logger here is one the caller provides.

Constructors

NetCordBridge(GatewayClient, ILogger?)

Wraps a NetCord.Gateway.GatewayClient, forwarding its voice events.

public NetCordBridge(GatewayClient client, ILogger? logger = null)

Parameters

client GatewayClient

The client to wrap.

logger ILogger

The logger to write the bridge's messages to.

NetCordBridge(ShardedGatewayClient, ILogger?)

Wraps a NetCord.Gateway.ShardedGatewayClient, forwarding the voice events of every shard.

public NetCordBridge(ShardedGatewayClient client, ILogger? logger = null)

Parameters

client ShardedGatewayClient

The sharded client to wrap.

logger ILogger

The logger to write the bridge's messages to.

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, with this bridge as the sender.

public event EventHandler<GuildRemovedEventArgs>? GuildRemoved

Event Type

EventHandler<GuildRemovedEventArgs>

VoiceServerUpdated

Raised when Discord allocates or re-targets the voice server of a guild, with this bridge as the sender.

public event EventHandler<VoiceServerUpdatedEventArgs>? VoiceServerUpdated

Event Type

EventHandler<VoiceServerUpdatedEventArgs>

VoiceStateUpdated

Raised when the voice state of the current user changes in a guild, with this bridge as the sender.

public event EventHandler<VoiceStateUpdatedEventArgs>? VoiceStateUpdated

Event Type

EventHandler<VoiceStateUpdatedEventArgs>