Repository: javacord/javacord
Issue: Javacord does not wait for all servers being loaded

Sometimes Javacord does not wait for all server being loaded on startup.
I don't know what's causing it, but I can imagine that it's caused by a slow websocket connection in combination with a very large server (Discord API has > 43.000 and Discord Bots > 37.000 members).
I feel like that there's something wrong in our handling, as we already wait a pretty long time.

```java
DiscordApi api = new DiscordApiBuilder()
        .setToken("nope")
        .login()
        .join();

System.out.println("Logged in");
```

```
2018-10-24 21:14:38,934 <DEBUG> <main> <[]> <{}> <org.javacord.core.DiscordApiBuilderDelegateImpl> Creating shard 1 of 1
2018-10-24 21:14:39,526 <DEBUG> <Javacord - Central ExecutorService - 2> <[]> <{shard=0}> <org.javacord.core.util.rest.RestRequest> Trying to send GET request to https://discordapp.com/api/v6/gateway
2018-10-24 21:14:39,872 <DEBUG> <Javacord - Central ExecutorService - 2> <[]> <{shard=0}> <org.javacord.core.util.rest.RestRequest> Sent GET request to https://discordapp.com/api/v6/gateway and received status code 200 with body {"url": "wss://gateway.discord.gg"}
2018-10-24 21:14:39,884 <DEBUG> <Javacord - Central ExecutorService - 2> <[]> <{shard=0}> <org.javacord.core.util.ratelimit.RatelimitManager> Calculated an offset of -872 to the Discord time.
2018-10-24 21:14:40,322 <DEBUG> <ReadingThread> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Received HELLO packet
2018-10-24 21:14:40,325 <DEBUG> <Javacord - Central Scheduler - 1> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Sent heartbeat (interval: 41250)
2018-10-24 21:14:40,325 <DEBUG> <ReadingThread> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Sending identify packet
2018-10-24 21:14:40,460 <DEBUG> <ReadingThread> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Heartbeat ACK received
2018-10-24 21:14:40,525 <DEBUG> <ReadingThread> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Received READY packet
2018-10-24 21:14:40,740 <DEBUG> <Javacord - Handlers Processor> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Queued Server (id: 151037561152733184, name: Javacord) for request guild members packet
2018-10-24 21:14:40,742 <DEBUG> <Javacord - Request Server Members Queue Consumer> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Sending request guild members packet {"op":8,"d":{"query":"","limit":0,"guild_id":"151037561152733184"}}
2018-10-24 21:14:44,539 <DEBUG> <Javacord - Central ExecutorService - 1> <[]> <{shard=0}> <org.javacord.core.util.rest.RestRequest> Trying to send GET request to https://discordapp.com/api/v6/oauth2/applications/@me
2018-10-24 21:14:44,686 <DEBUG> <Javacord - Central ExecutorService - 1> <[]> <{shard=0}> <org.javacord.core.util.rest.RestRequest> Sent GET request to https://discordapp.com/api/v6/oauth2/applications/@me and received status code 200 with body {"description": "", "name": "Bastians Bot", "owner": {"username": "Bastian", "discriminator": "0001", "id": "157862224206102529", "avatar": "a_796bef60840438a232f53f24ba29165c"}, "bot_public": true, "bot_require_code_grant": false, "id": "157889000391180288", "icon": "a20d7ce51ae6bb0e3ef78195468e0d46"}
2018-10-24 21:14:44,687 <DEBUG> <Javacord - Central ExecutorService - 1> <[]> <{shard=0}> <org.javacord.core.util.ratelimit.RatelimitManager> Calculated an offset of -686 to the Discord time.
Logged in
2018-10-24 21:14:44,732 <DEBUG> <Javacord - Handlers Processor> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Queued Server (id: 110373943822540800, name: Discord Bots) for request guild members packet
2018-10-24 21:14:44,732 <DEBUG> <Javacord - Request Server Members Queue Consumer> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Sending request guild members packet {"op":8,"d":{"query":"","limit":0,"guild_id":"110373943822540800"}}
2018-10-24 21:14:49,169 <DEBUG> <Javacord - Handlers Processor> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Queued Server (id: 81384788765712384, name: Discord API) for request guild members packet
2018-10-24 21:14:49,169 <DEBUG> <Javacord - Request Server Members Queue Consumer> <[]> <{shard=0}> <org.javacord.core.util.gateway.DiscordWebSocketAdapter> Sending request guild members packet {"op":8,"d":{"query":"","limit":0,"guild_id":"81384788765712384"}}
```

Changed files:
javacord-core/src/main/java/org/javacord/core/util/gateway/DiscordWebSocketAdapter.java

diff --git a/javacord-core/src/main/java/org/javacord/core/util/gateway/DiscordWebSocketAdapter.java b/javacord-core/src/main/java/org/javacord/core/util/gateway/DiscordWebSocketAdapter.java
index 4654b9eb..9a1cb57a 100644
--- a/javacord-core/src/main/java/org/javacord/core/util/gateway/DiscordWebSocketAdapter.java
+++ b/javacord-core/src/main/java/org/javacord/core/util/gateway/DiscordWebSocketAdapter.java
@@ -529,9 +529,9 @@ public class DiscordWebSocketAdapter extends WebSocketAdapter {
                                 allUsersLoaded = api.getAllServers().stream()
                                         .noneMatch(server -> server.getMemberCount() != server.getMembers().size());
                             }
-                            if (sameUnavailableServerCounter > 20
+                            if (sameUnavailableServerCounter > 1000
                                     && lastGuildMembersChunkReceived + 5000 < System.currentTimeMillis()) {
-                                // It has been more than two seconds since no more servers became available and more
+                                // It has been more than 1 minute since no more servers became available and more
                                 // than five seconds since the last guild member chunk event was received. We
                                 // can assume that this will not change anytime soon, most likely because Discord
                                 // itself has some issues. Let's break the loop!