diff --git a/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs b/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs index af16f22f59..1e0bf71c2e 100644 --- a/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs +++ b/src/Discord.Net.WebSocket/API/Gateway/IdentifyParams.cs @@ -15,5 +15,7 @@ internal class IdentifyParams public int LargeThreshold { get; set; } [JsonProperty("shard")] public Optional ShardingParams { get; set; } + [JsonProperty("guild_subscriptions")] + public Optional GuildSubscriptions { get; set; } } } diff --git a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs index 88ef1134e0..9313f07116 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketApiClient.cs @@ -215,7 +215,7 @@ private async Task SendGatewayInternalAsync(GatewayOpCode opCode, object payload await _sentGatewayMessageEvent.InvokeAsync(opCode).ConfigureAwait(false); } - public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, RequestOptions options = null) + public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, int totalShards = 1, bool guildSubscriptions = true, RequestOptions options = null) { options = RequestOptions.CreateOrClone(options); var props = new Dictionary @@ -226,7 +226,8 @@ public async Task SendIdentifyAsync(int largeThreshold = 100, int shardID = 0, i { Token = AuthToken, Properties = props, - LargeThreshold = largeThreshold + LargeThreshold = largeThreshold, + GuildSubscriptions = guildSubscriptions }; if (totalShards > 1) msg.ShardingParams = new int[] { shardID, totalShards }; diff --git a/src/Discord.Net.WebSocket/DiscordSocketClient.cs b/src/Discord.Net.WebSocket/DiscordSocketClient.cs index b25f611565..ed142d001b 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketClient.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketClient.cs @@ -43,6 +43,7 @@ public partial class DiscordSocketClient : BaseSocketClient, IDiscordClient private DateTimeOffset? _statusSince; private RestApplication _applicationInfo; private bool _isDisposed; + private bool _guildSubscriptions; /// /// Provides access to a REST-only client with a shared state from this client. @@ -135,6 +136,7 @@ private DiscordSocketClient(DiscordSocketConfig config, API.DiscordSocketApiClie State = new ClientState(0, 0); Rest = new DiscordSocketRestClient(config, ApiClient); _heartbeatTimes = new ConcurrentQueue(); + _guildSubscriptions = config.GuildSubscriptions; _stateLock = new SemaphoreSlim(1, 1); _gatewayLogger = LogManager.CreateLogger(ShardId == 0 && TotalShards == 1 ? "Gateway" : $"Shard #{ShardId}"); @@ -240,7 +242,7 @@ private async Task OnConnectingAsync() else { await _gatewayLogger.DebugAsync("Identifying").ConfigureAwait(false); - await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards).ConfigureAwait(false); + await ApiClient.SendIdentifyAsync(shardID: ShardId, totalShards: TotalShards, guildSubscriptions: _guildSubscriptions).ConfigureAwait(false); } //Wait for READY diff --git a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs index 3610afd134..98ab0ef9b7 100644 --- a/src/Discord.Net.WebSocket/DiscordSocketConfig.cs +++ b/src/Discord.Net.WebSocket/DiscordSocketConfig.cs @@ -77,7 +77,7 @@ public class DiscordSocketConfig : DiscordRestConfig /// /// By default, the Discord gateway will only send offline members if a guild has less than a certain number /// of members (determined by in this library). This behaviour is why - /// sometimes a user may be missing from the WebSocket cache for collections such as + /// sometimes a user may be missing from the WebSocket cache for collections such as /// . /// /// @@ -86,7 +86,7 @@ public class DiscordSocketConfig : DiscordRestConfig /// downloaded to the WebSocket cache. /// /// - /// For more information, please see + /// For more information, please see /// Request Guild Members /// on the official Discord API documentation. /// @@ -95,7 +95,7 @@ public class DiscordSocketConfig : DiscordRestConfig /// traffic. If you are using the command system, the default user TypeReader may fail to find the user /// due to this issue. This may be resolved at v3 of the library. Until then, you may want to consider /// overriding the TypeReader and use - /// + /// /// or /// as a backup. /// @@ -119,6 +119,11 @@ public class DiscordSocketConfig : DiscordRestConfig /// public bool? ExclusiveBulkDelete { get; set; } = null; + /// + /// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events. + /// + public bool GuildSubscriptions { get; set; } = true; + /// /// Initializes a default configuration. ///