Class DiscordSocketConfig
Represents a configuration class for DiscordSocketClient.
Inherited Members
Namespace: Discord.WebSocket
Assembly: Discord.Net.WebSocket.dll
Syntax
public class DiscordSocketConfig : DiscordRestConfig
Remarks
This configuration, based on DiscordRestConfig, helps determine several key configurations the socket client depend on. For instance, shards and connection timeout.
Examples
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);
Constructors
| Improve this Doc View SourceDiscordSocketConfig()
Initializes a default configuration.
Declaration
public DiscordSocketConfig()
Fields
| Improve this Doc View SourceGatewayEncoding
Returns the encoding gateway should use.
Declaration
public const string GatewayEncoding = "json"
Field Value
| Type | Description |
|---|---|
| System.String |
Properties
| Improve this Doc View SourceAlwaysDownloadUsers
Gets or sets whether or not all users should be downloaded as guilds come available.
Declaration
public bool AlwaysDownloadUsers { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
Remarks
By default, the Discord gateway will only send offline members if a guild has less than a certain number of members (determined by LargeThreshold in this library). This behaviour is why sometimes a user may be missing from the WebSocket cache for collections such as Users.
This property ensures that whenever a guild becomes available (determined by GuildAvailable), incomplete user chunks will be downloaded to the WebSocket cache.
For more information, please see Request Guild Members on the official Discord API documentation.
note
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 GetUserAsync(UInt64, RequestOptions) or GetGuildUserAsync(UInt64, UInt64, RequestOptions) as a backup.
ConnectionTimeout
Gets or sets the time, in milliseconds, to wait for a connection to complete before aborting.
Declaration
public int ConnectionTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
ExclusiveBulkDelete
Gets or sets the behavior for MessageDeleted on bulk deletes.
If true, the MessageDeleted event will not be raised for bulk deletes, and only the MessagesBulkDeleted 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.
Declaration
public bool? ExclusiveBulkDelete { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Boolean> |
GatewayHost
Gets or sets the WebSocket host to connect to. If null, the client will use the
/gateway endpoint.
Declaration
public string GatewayHost { get; set; }
Property Value
| Type | Description |
|---|---|
| System.String |
GuildSubscriptions
Gets or sets enabling dispatching of guild subscription events e.g. presence and typing events.
Declaration
public bool GuildSubscriptions { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Boolean |
HandlerTimeout
Gets or sets the timeout for event handlers, in milliseconds, after which a warning will be logged. Null disables this check.
Declaration
public int? HandlerTimeout { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Int32> |
LargeThreshold
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.
Declaration
public int LargeThreshold { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
MessageCacheSize
Gets or sets the number of messages per channel that should be kept in cache. Setting this to zero disables the message cache entirely.
Declaration
public int MessageCacheSize { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Int32 |
ShardId
Gets or sets the ID for this shard. Must be less than TotalShards.
Declaration
public int? ShardId { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Int32> |
TotalShards
Gets or sets the total number of shards for this application.
Declaration
public int? TotalShards { get; set; }
Property Value
| Type | Description |
|---|---|
| System.Nullable<System.Int32> |
UdpSocketProvider
Gets or sets the provider used to generate new UDP sockets.
Declaration
public UdpSocketProvider UdpSocketProvider { get; set; }
Property Value
| Type | Description |
|---|---|
| Discord.Net.Udp.UdpSocketProvider |
WebSocketProvider
Gets or sets the provider used to generate new WebSocket connections.
Declaration
public WebSocketProvider WebSocketProvider { get; set; }
Property Value
| Type | Description |
|---|---|
| Discord.Net.WebSockets.WebSocketProvider |