Skip to content

Add shard concurrency + massive DiscordShardedClient rework

Created by: Neuheit

Summary

Fixes #569 (closed), and reworks much of the sharding client. Fixes #546 (closed).

Details

Aside from resolving these two issues, this PR adds a few new methods/changes:

StopAsync() - will disconnect and dispose of all shards, while also unregistering their event handlers. GetShard() - provides a cacheless method to fetch a shard according to Discord's sharding formula.

GetGatewayInfoAsync() - this was added as a public method for the BaseDiscordClient, and a private method on the sharding client.

Additionally, StartAsync() was reworked to provide support for concurrency by reducing the number of REST requests. Previously, the sharding client would make all of it's clients call GET gateway/bot, which would have not worked with concurrency due to its session rate limit. This is now changed to only call it once and cache it for all shards.

Changes proposed

  • Resolve the issues above.
  • Rework the sharding client to provide more convenient methods.
  • Reduced the number of requests in order to support concurrency.
  • Also included a few WS checks to eliminate exceptions being thrown there.

Notes

The only thing with the gateway info is that it will not be updated by D#+. In order to do so we would need to continuously make requests to GET gateway/bot, which is unneeded, especially considering the majority of users will never use it. Even if they do, it also wouldn't be hard for them to call it and get the information themselves.

Merge request reports

Loading