diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
index d4754d7d..161fff3a 100644
--- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs
+++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs
@@ -83,6 +83,7 @@ namespace Discord.WebSocket
internal bool AlwaysResolveStickers { get; private set; }
internal bool LogGatewayIntentWarnings { get; private set; }
internal bool SuppressUnknownDispatchWarnings { get; private set; }
+ internal bool IncludeRawPayloadOnGatewayErrors { get; private set; }
internal int AuditLogCacheSize { get; private set; }
internal new DiscordSocketApiClient ApiClient => base.ApiClient;
@@ -158,6 +159,7 @@ namespace Discord.WebSocket
AlwaysResolveStickers = config.AlwaysResolveStickers;
LogGatewayIntentWarnings = config.LogGatewayIntentWarnings;
SuppressUnknownDispatchWarnings = config.SuppressUnknownDispatchWarnings;
+ IncludeRawPayloadOnGatewayErrors = config.IncludeRawPayloadOnGatewayErrors;
HandlerTimeout = config.HandlerTimeout;
State = new ClientState(0, 0);
Rest = new DiscordSocketRestClient(config, ApiClient);
@@ -3342,6 +3344,13 @@ namespace Discord.WebSocket
}
catch (Exception ex)
{
+ if (IncludeRawPayloadOnGatewayErrors)
+ {
+ ex.Data["opcode"] = opCode;
+ ex.Data["type"] = type;
+ ex.Data["payload_data"] = (payload as JToken).ToString();
+ }
+
await _gatewayLogger.ErrorAsync($"Error handling {opCode}{(type != null ? $" ({type})" : "")}", ex).ConfigureAwait(false);
}
}
diff --git a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs
index 21f21a28..01849b72 100644
--- a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs
+++ b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs
@@ -176,6 +176,15 @@ namespace Discord.WebSocket
}
}
+ ///
+ /// Gets or sets whether or not to include the raw payload on gateway errors.
+ ///
+ ///
+ /// Note that this may expose sensitive information to logs. It is recommended to only enable this in
+ /// cases where you are actively debugging an issue.
+ ///
+ public bool IncludeRawPayloadOnGatewayErrors { get; set; } = false;
+
private int maxWaitForGuildAvailable = 10000;
///