public void SocketClosed(object sender, CloseEventArgs e) { if (e.Code == 4004) { Interface.Oxide.LogError("[Discord Extension] Given Bot token is invalid!"); throw new APIKeyException(); } if (client.Settings.Debugging) { Interface.Oxide.LogDebug($"Discord WebSocket closed. Code: {e.Code}, reason: {e.Reason}"); } if (client.requestReconnect) { client.requestReconnect = false; webSocket.Connect(client.WSSURL); return; } if (e.Code == 4006) { webSocket.hasConnectedOnce = false; Interface.Oxide.LogWarning("[Discord Extension] Discord session no longer valid... Reconnecting..."); client.REST.Shutdown(); // Clean up buckets webSocket.Connect(client.WSSURL); client.CallHook("DiscordSocket_WebSocketClosed", null, e.Reason, e.Code, e.WasClean); return; } if (!e.WasClean) { Interface.Oxide.LogWarning($"[Discord Extension] Discord connection closed uncleanly: code {e.Code}, Reason: {e.Reason}"); if (retries >= 5) { Interface.Oxide.LogError("[Discord Extension] Exceeded number of retries... Attempting in 15 seconds."); Timer reconnecttimer = new Timer() { Interval = 15000f, AutoReset = false }; reconnecttimer.Elapsed += (object a, ElapsedEventArgs b) => { if (client == null) { return; } retries = 0; Interface.Oxide.LogWarning($"[Discord Extension] Attempting to reconnect to Discord..."); client.REST.Shutdown(); // Clean up buckets webSocket.Connect(client.WSSURL); }; reconnecttimer.Start(); return; } retries++; Interface.Oxide.LogWarning($"[Discord Extension] Attempting to reconnect to Discord..."); client.REST.Shutdown(); // Clean up buckets webSocket.Connect(client.WSSURL); } else { Discord.CloseClient(client); } client.CallHook("DiscordSocket_WebSocketClosed", null, e.Reason, e.Code, e.WasClean); }