Class DiscordNetBridge
- Namespace
- Nyra.DiscordNet
- Assembly
- Nyra.DiscordNet.dll
Wraps a Discord.WebSocket.DiscordSocketClient or Discord.WebSocket.DiscordShardedClient for Nyra.
public sealed class DiscordNetBridge : IDiscordBridge, IGuildRemovalSource, IDisposable
- Inheritance
-
DiscordNetBridge
- Implements
- Inherited Members
Remarks
The voice state update goes through Discord.Net's public external-audio route, so the bridge keeps the audio channel of each guild to disconnect from later.
Constructors
DiscordNetBridge(DiscordShardedClient, ILogger?)
Wraps a Discord.WebSocket.DiscordShardedClient, forwarding the voice events of every shard.
public DiscordNetBridge(DiscordShardedClient client, ILogger? logger = null)
Parameters
clientDiscordShardedClientThe sharded client to wrap.
loggerILoggerThe logger to write the library's messages through, Discord.Net ships no logger.
DiscordNetBridge(DiscordSocketClient, ILogger?)
Wraps a Discord.WebSocket.DiscordSocketClient, forwarding its voice events.
public DiscordNetBridge(DiscordSocketClient client, ILogger? logger = null)
Parameters
clientDiscordSocketClientThe client to wrap.
loggerILoggerThe logger to write the library's messages through, Discord.Net ships no logger.
Properties
Logger
The bridge's logger, or null when neither the library nor the caller provides one.
public ILogger? Logger { get; }
Property Value
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
guildIdulongThe guild to send the voice state update in.
channelIdulong?The voice channel to join, null leaves the voice channel.
selfDeafboolWhether 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.
selfMuteboolWhether 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.cancellationTokenCancellationTokenA 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
cancellationTokenCancellationTokenA 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
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
VoiceStateUpdated
Raised when the voice state of the current user changes in a guild.
public event EventHandler<VoiceStateUpdatedEventArgs>? VoiceStateUpdated