Class DiscordClientExtensions
- Namespace
- Nyra.DSharpPlus
- Assembly
- Nyra.DSharpPlus.dll
Entry points for enabling, accessing, and removing Nyra on DSharpPlus clients.
public static class DiscordClientExtensions
- Inheritance
-
DiscordClientExtensions
- Inherited Members
Methods
GetNyra(DiscordClient)
Gets the Nyra extension of the client, or null when Nyra is not enabled.
public static NyraExtension? GetNyra(this DiscordClient client)
Parameters
clientDiscordClientThe client to read the extension of.
Returns
- NyraExtension
The extension of the client, null when Nyra is not enabled.
GetNyraAsync(DiscordShardedClient)
Gets the Nyra extensions of all initialized shards.
public static Task<IReadOnlyDictionary<int, NyraExtension>> GetNyraAsync(this DiscordShardedClient client)
Parameters
clientDiscordShardedClientThe sharded client to read the extensions of.
Returns
- Task<IReadOnlyDictionary<int, NyraExtension>>
The extensions of the initialized shards, keyed by shard id.
Remarks
This is not a pure read, an uninitialized sharded client initializes here, which does gateway I/O, can throw the library's raw auth error on a bad token and can hang on rate limits. Call it on an already started client for a pure read.
RemoveNyra(DiscordClient)
Disposes the client's Nyra extension and forgets it, the Discord client itself is left running.
public static void RemoveNyra(this DiscordClient client)
Parameters
clientDiscordClientThe client whose Nyra extension to remove.
Remarks
A stop of the sharded client destroys its shard objects without disposing their extensions. The
orphaned fleet stays alive on the dead shards, and a later StartAsync builds fresh shards whose
extensions know nothing of it, so a second UseNyra there races the old fleet's node sessions. Call this
per shard before stopping or recycling a sharded client, or dispose the extensions UseNyra returned.
RemoveNyraAsync(DiscordClient)
Removes the client's Nyra extension and disposes it without blocking the caller.
public static Task RemoveNyraAsync(this DiscordClient client)
Parameters
clientDiscordClientThe client whose Nyra extension to remove.
Returns
- Task
A task that completes when the extension was removed and disposed.
Remarks
The awaitable counterpart of RemoveNyra(DiscordClient), the dispose tears every node down in parallel instead of blocking a sync caller for the whole bound, prefer it on shutdown paths that can await.
UseNyra(DiscordClient)
Enables Nyra on the client.
public static NyraExtension UseNyra(this DiscordClient client)
Parameters
clientDiscordClientThe client to enable Nyra on.
Returns
- NyraExtension
The enabled extension, the existing one when Nyra is already on.
UseNyra(DiscordClient, int?)
Enables Nyra on a manually sharded client.
public static NyraExtension UseNyra(this DiscordClient client, int? shardCount)
Parameters
clientDiscordClientThe client to enable Nyra on.
shardCountint?The total number of shards the fleet runs.
Returns
- NyraExtension
The enabled extension, the existing one when Nyra is already on.
Remarks
Pass the total so the bridge can reject guilds of another shard, without it the join times out with a misleading permission error. Use the sharded client's own entry point instead when the shards live in one process.
UseNyraAsync(DiscordShardedClient)
Enables Nyra on every shard of the sharded client.
public static Task<IReadOnlyDictionary<int, NyraExtension>> UseNyraAsync(this DiscordShardedClient client)
Parameters
clientDiscordShardedClientThe sharded client to enable Nyra on, one extension per shard.
Returns
- Task<IReadOnlyDictionary<int, NyraExtension>>
The extensions of the shards, keyed by shard id.
Remarks
A shard already enabled on its own keeps it, but without the sharded total it cannot reject foreign guilds and is flagged with a warning.
Stopping the sharded client destroys its shard objects without disposing these extensions. The orphaned fleet stays alive on the dead shards, GetNyraAsync on the restarted client reports nothing, and a second UseNyraAsync builds a new fleet whose nodes fight the old one's sessions for the same user id. Call RemoveNyra (or dispose the extensions this returns) on every shard before stopping or recycling the client.