using Discord.Net.Udp; using Discord.Net.WebSockets; using Discord.Rest; namespace Discord.WebSocket { /// /// Represents a configuration class for . /// /// /// This configuration, based on , helps determine several key configurations the /// socket client depend on. For instance, shards and connection timeout. /// /// /// The following config enables the message cache and configures the client to always download user upon guild /// availability. /// /// var config = new DiscordSocketConfig /// { /// AlwaysDownloadUsers = true, /// MessageCacheSize = 100 /// }; /// var client = new DiscordSocketClient(config); /// /// public class DiscordSocketConfig : DiscordRestConfig { /// /// Returns the encoding gateway should use. /// public const string GatewayEncoding = "json"; /// /// Gets or sets the WebSocket host to connect to. If null, the client will use the /// /gateway endpoint. /// public string GatewayHost { get; set; } = null; /// /// Gets or sets the time, in milliseconds, to wait for a connection to complete before aborting. /// public int ConnectionTimeout { get; set; } = 30000; /// /// Gets or sets the ID for this shard. Must be less than . /// public int? ShardId { get; set; } = null; /// /// Gets or sets the total number of shards for this application. /// public int? TotalShards { get; set; } = null; /// /// Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero /// disables the message cache entirely. /// public int MessageCacheSize { get; set; } = 0; /// /// Gets or sets the max number of users a guild may have for offline users to be included in the READY /// packet. Max is 250. /// public int LargeThreshold { get; set; } = 250; /// /// Gets or sets the provider used to generate new WebSocket connections. /// public WebSocketProvider WebSocketProvider { get; set; } /// /// Gets or sets the provider used to generate new UDP sockets. /// public UdpSocketProvider UdpSocketProvider { get; set; } /// /// Gets or sets whether or not all users should be downloaded as guilds come available. /// /// /// /// 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 /// . /// /// /// This property ensures that whenever a guild becomes available (determined by /// ), incomplete user chunks will be /// downloaded to the WebSocket cache. /// /// /// For more information, please see /// Request Guild Members /// on the official Discord API documentation. /// /// /// Please note that it can be difficult to fill the cache completely on large guilds depending on the /// 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. /// /// public bool AlwaysDownloadUsers { get; set; } = false; /// /// Gets or sets the timeout for event handlers, in milliseconds, after which a warning will be logged. Null /// disables this check. /// public int? HandlerTimeout { get; set; } = 3000; /// /// Gets or sets the behavior for on bulk deletes. /// /// If true, the event will not be raised for bulk deletes, and /// only the will be raised. /// /// If false, both events will be raised. /// /// If unset, both events will be raised, but a warning will be raised the first time a bulk delete event is received. /// public bool? ExclusiveBulkDelete { get; set; } = null; /// /// Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events. /// This is not used if are provided. /// public bool GuildSubscriptions { get; set; } = true; /// /// Gets or sets the maximum wait time in milliseconds between GUILD_AVAILABLE events before firing READY. /// /// If zero, READY will fire as soon as it is received and all guilds will be unavailable. /// /// /// This property is measured in milliseconds, negative values will throw an exception. /// If a guild is not received before READY, it will be unavailable. /// /// /// The maximum wait time in milliseconds between GUILD_AVAILABLE events before firing READY. /// /// Value must be at least 0. public int MaxWaitBetweenGuildAvailablesBeforeReady { get { return _maxWaitForGuildAvailable; } set { Preconditions.AtLeast(value, 0, nameof(MaxWaitBetweenGuildAvailablesBeforeReady)); _maxWaitForGuildAvailable = value; } } private int _maxWaitForGuildAvailable = 10000; /// Gets or sets gateway intents to limit what events are sent from Discord. Allows for more granular control than the property. /// /// /// For more information, please see /// GatewayIntents /// on the official Discord API documentation. /// public GatewayIntents? GatewayIntents { get; set; } /// /// Initializes a default configuration. /// public DiscordSocketConfig() { WebSocketProvider = DefaultWebSocketProvider.Instance; UdpSocketProvider = DefaultUdpSocketProvider.Instance; } internal DiscordSocketConfig Clone() => MemberwiseClone() as DiscordSocketConfig; } }