diff --git a/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs b/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
index f3141e56c..ffa5feb44 100644
--- a/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
+++ b/src/Discord.Net/API/Client/GatewaySocket/Commands/Identify.cs
@@ -18,5 +18,7 @@ namespace Discord.API.Client.GatewaySocket
public int LargeThreshold { get; set; }
[JsonProperty("compress")]
public bool UseCompression { get; set; }
+ [JsonProperty("shard")]
+ public int[] ShardingParams { get; set; }
}
}
diff --git a/src/Discord.Net/DiscordConfig.cs b/src/Discord.Net/DiscordConfig.cs
index c7a754812..e81d2efae 100644
--- a/src/Discord.Net/DiscordConfig.cs
+++ b/src/Discord.Net/DiscordConfig.cs
@@ -47,6 +47,11 @@ namespace Discord
///
public int LargeThreshold { get; set; } = 250;
+ /// Gets or sets the id for this shard. Must be less than TotalShards.
+ public int ShardId { get; set; } = 0;
+ /// Gets or sets the total number of shards for this application.
+ public int TotalShards { get; set; } = 1;
+
//Events
/// Gets or sets a handler for all log messages.
@@ -89,6 +94,9 @@ namespace Discord
public bool UsePermissionsCache { get; }
public bool EnablePreUpdateEvents { get; }
+ public int ShardId { get; }
+ public int TotalShards { get; }
+
internal DiscordConfig(DiscordConfigBuilder builder)
{
LogLevel = builder.LogLevel;
@@ -106,6 +114,8 @@ namespace Discord
MessageCacheSize = builder.MessageCacheSize;
UsePermissionsCache = builder.UsePermissionsCache;
EnablePreUpdateEvents = builder.EnablePreUpdateEvents;
+ ShardId = builder.ShardId;
+ TotalShards = builder.TotalShards;
}
private static string GetUserAgent(DiscordConfigBuilder builder)
diff --git a/src/Discord.Net/Net/Rest/RestClient.cs b/src/Discord.Net/Net/Rest/RestClient.cs
index f5e1a6471..952feed5c 100644
--- a/src/Discord.Net/Net/Rest/RestClient.cs
+++ b/src/Discord.Net/Net/Rest/RestClient.cs
@@ -51,6 +51,9 @@ namespace Discord.Net.Rest
}
}
+ public int ShardId => _config.ShardId;
+ public int TotalShards => _config.TotalShards;
+
protected RestClient(DiscordConfig config, string baseUrl, ILogger logger = null)
{
_config = config;
diff --git a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
index 33f890878..d9f7bf520 100644
--- a/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
+++ b/src/Discord.Net/Net/WebSockets/GatewaySocket.cs
@@ -50,7 +50,7 @@ namespace Discord.Net.WebSockets
Host = url;
await BeginConnect(parentCancelToken).ConfigureAwait(false);
if (SessionId == null)
- SendIdentify(_rest.Token);
+ SendIdentify(_rest.Token, _rest.ShardId, _rest.TotalShards);
else
SendResume();
}
@@ -148,7 +148,7 @@ namespace Discord.Net.WebSockets
}
}
- public void SendIdentify(string token)
+ public void SendIdentify(string token, int shardId = 0, int totalShards = 1)
{
var props = new Dictionary
{
@@ -159,9 +159,11 @@ namespace Discord.Net.WebSockets
Token = token,
Properties = props,
LargeThreshold = _config.LargeThreshold,
- UseCompression = true
+ UseCompression = true,
+ ShardingParams = new int[] { shardId, totalShards },
};
- QueueMessage(msg);
+
+ QueueMessage(msg);
}
public void SendResume()