From 4f16f12efc00a88179ada3d00e8047404879bb0f Mon Sep 17 00:00:00 2001 From: Christopher F Date: Thu, 7 Apr 2016 19:19:23 -0400 Subject: [PATCH] READY won't fire until all GUILD_CREATES are received really ugly fix for a few of the major discord.net bots that were crashing during startup and/or had 0 servers in their READY event. --- src/Discord.Net/DiscordClient.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Discord.Net/DiscordClient.cs b/src/Discord.Net/DiscordClient.cs index bc9c2f537..0fa95d549 100644 --- a/src/Discord.Net/DiscordClient.cs +++ b/src/Discord.Net/DiscordClient.cs @@ -34,6 +34,8 @@ namespace Discord private Dictionary _regions; private Stopwatch _connectionStopwatch; + private int _readyServerCount; + internal Logger Logger { get; } /// Gets the configuration object used to make this client. @@ -493,6 +495,8 @@ namespace Discord _channels = new ConcurrentDictionary(2, (int)(data.Guilds.Length * 2 * 1.05)); _privateChannels = new ConcurrentDictionary(2, (int)(data.PrivateChannels.Length * 1.05)); + _readyServerCount = data.Guilds.Length; + SessionId = data.SessionId; PrivateUser = new User(this, data.User.Id, null); PrivateUser.Update(data.User); @@ -514,7 +518,8 @@ namespace Discord var channel = AddPrivateChannel(model.Id, model.Recipient.Id); channel.Update(model); } - EndConnect(); + Log.Info("Discord", "READY was processed, holding off to raise event until servers are filled."); + //EndConnect(); } break; @@ -540,6 +545,8 @@ namespace Discord OnServerAvailable(server); } } + if (State == ConnectionState.Connecting && Servers.Count() >= _readyServerCount) + EndConnect(); } break; case "GUILD_UPDATE":