DiscordShardClient NRE Fix + Minor Code Fixes
Created by: Neuheit
Summary
Fixes an NRE thrown when trying to register shard client event handlers, as well as minor cleanup and WebSocket client improvements.
Details
This fixes an issue reported by Lymdun#9640 on Discord which would throw a NullReferenceException when trying to register an event handler with the DiscordShardedClient. This was caused by my previous PR, because I was moving around internal event registering/deregistering but forgot to move event handler initialization back to the constructor. Additionally, I reorganized a little bit of the code by moving event registering/deregistering into their own separate functions, and moving event initialization/handling at the bottom of the class.
On another note, I also added a few WS message send/close checks to ensure those proper operations are invoked/occur.
Changes proposed
- Fix NRE in shard client.
- Clean up code a little bit in the sharding client.
- Improve WebSocket client handling.