Skip to main content

Class DiscordSocketClient

Represents a WebSocket-based Discord client.

Assembly: Discord.Net.WebSocket.dll​
View Source​
Declaration
public class DiscordSocketClient : BaseSocketClient, IDiscordClient, IDisposable

Properties​

Rest​

Provides access to a REST-only client with a shared state from this client.

View Source​
Declaration
public override DiscordSocketRestClient Rest { get; }

ShardId​

Gets the shard of this client.

View Source​
Declaration
public int ShardId { get; }

ConnectionState​

Gets the current connection state of this client.

View Source​
Declaration
public ConnectionState ConnectionState { get; }

Latency​

Gets the estimated round-trip latency, in milliseconds, to the gateway server.

View Source​
Declaration
public override int Latency { get; protected set; }

Status​

Gets the status for the logged-in user.

View Source​
Declaration
public override UserStatus Status { get; protected set; }

Activity​

Gets the activity for the logged-in user.

View Source​
Declaration
public override IActivity Activity { get; protected set; }

Guilds​

Gets a collection of guilds that the user is currently in.

View Source​
Declaration
public override IReadOnlyCollection<SocketGuild> Guilds { get; }

DefaultStickerPacks​

Gets a collection of default stickers.

View Source​
Declaration
public override IReadOnlyCollection<StickerPack<SocketSticker>> DefaultStickerPacks { get; }

PrivateChannels​

Gets a collection of private channels opened in this session.

View Source​
Declaration
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels { get; }

DMChannels​

Gets a collection of direct message channels opened in this session.

View Source​
Declaration
public IReadOnlyCollection<SocketDMChannel> DMChannels { get; }

GroupChannels​

Gets a collection of group channels opened in this session.

View Source​
Declaration
public IReadOnlyCollection<SocketGroupChannel> GroupChannels { get; }

Methods​

StartAsync()​

Starts the connection between Discord and the client..

View Source​
Declaration
public override async Task StartAsync()
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous start operation.

StopAsync()​

Stops the connection between Discord and the client.

View Source​
Declaration
public override async Task StopAsync()
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous stop operation.

GetApplicationInfoAsync(RequestOptions)​

Gets a Discord application information for the logged-in user.

View Source​
Declaration
public override async Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
Returns​

System.Threading.Tasks.Task<Discord.Rest.RestApplication>: A task that represents the asynchronous get operation. The task result contains the application information.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

GetGuild(UInt64)​

Gets a guild.

View Source​
Declaration
public override SocketGuild GetGuild(ulong id)
Returns​

Discord.WebSocket.SocketGuild: A WebSocket-based guild associated with the snowflake identifier; null when the guild cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe guild snowflake identifier.

GetChannel(UInt64)​

Gets a channel.

View Source​
Declaration
public override SocketChannel GetChannel(ulong id)
Returns​

Discord.WebSocket.SocketChannel: A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier; null when the channel cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe snowflake identifier of the channel (e.g. 381889909113225237).

GetChannelAsync(UInt64, RequestOptions)​

Gets a generic channel from the cache or does a rest request if unavailable.

View Source​
Declaration
public async ValueTask<IChannel> GetChannelAsync(ulong id, RequestOptions options = null)
Returns​

System.Threading.Tasks.ValueTask<Discord.IChannel>: A task that represents the asynchronous get operation. The task result contains the channel associated with the snowflake identifier; null when the channel cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe snowflake identifier of the channel (e.g. 381889909113225237).
Discord.RequestOptionsoptionsThe options to be used when sending the request.

GetUserAsync(UInt64, RequestOptions)​

Gets a user from the cache or does a rest request if unavailable.

View Source​
Declaration
public async ValueTask<IUser> GetUserAsync(ulong id, RequestOptions options = null)
Returns​

System.Threading.Tasks.ValueTask<Discord.IUser>: A task that represents the asynchronous get operation. The task result contains the user associated with the snowflake identifier; null if the user is not found.

Parameters​
TypeNameDescription
System.UInt64idThe snowflake identifier of the user (e.g. 168693960628371456).
Discord.RequestOptionsoptionsThe options to be used when sending the request.

PurgeChannelCache()​

Clears all cached channels from the client.

View Source​
Declaration
public void PurgeChannelCache()

PurgeDMChannelCache()​

Clears cached DM channels from the client.

View Source​
Declaration
public void PurgeDMChannelCache()

GetUser(UInt64)​

Gets a generic user.

View Source​
Declaration
public override SocketUser GetUser(ulong id)
Returns​

Discord.WebSocket.SocketUser: A generic WebSocket-based user; null when the user cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe user snowflake ID.

GetUser(String, String)​

Gets a user.

View Source​
Declaration
public override SocketUser GetUser(string username, string discriminator)
Returns​

Discord.WebSocket.SocketUser: A generic WebSocket-based user; null when the user cannot be found.

Parameters​
TypeNameDescription
System.StringusernameThe name of the user.
System.StringdiscriminatorThe discriminator value of the user.

GetGlobalApplicationCommandAsync(UInt64, RequestOptions)​

Gets a global application command.

View Source​
Declaration
public async ValueTask<SocketApplicationCommand> GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null)
Returns​

System.Threading.Tasks.ValueTask<Discord.WebSocket.SocketApplicationCommand>: A ValueTask that represents the asynchronous get operation. The task result contains the application command if found, otherwise null.

Parameters​
TypeNameDescription
System.UInt64idThe id of the command.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

GetGlobalApplicationCommandsAsync(RequestOptions)​

Gets a collection of all global commands.

View Source​
Declaration
public async Task<IReadOnlyCollection<SocketApplicationCommand>> GetGlobalApplicationCommandsAsync(RequestOptions options = null)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.WebSocket.SocketApplicationCommand>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of global application commands.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

CreateGlobalApplicationCommandAsync(ApplicationCommandProperties, RequestOptions)​

View Source​
Declaration
public async Task<SocketApplicationCommand> CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
Returns​

System.Threading.Tasks.Task<Discord.WebSocket.SocketApplicationCommand>

Parameters​
TypeName
Discord.ApplicationCommandPropertiesproperties
Discord.RequestOptionsoptions

BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[], RequestOptions)​

View Source​
Declaration
public async Task<IReadOnlyCollection<SocketApplicationCommand>> BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[] properties, RequestOptions options = null)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.WebSocket.SocketApplicationCommand>>

Parameters​
TypeName
Discord.ApplicationCommandProperties[]properties
Discord.RequestOptionsoptions

PurgeUserCache()​

Clears cached users from the client.

View Source​
Declaration
public void PurgeUserCache()

GetStickerAsync(UInt64, CacheMode, RequestOptions)​

Gets a sticker.

View Source​
Declaration
public override async Task<SocketSticker> GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Returns​

System.Threading.Tasks.Task<Discord.WebSocket.SocketSticker>: A Discord.WebSocket.SocketSticker if found, otherwise null.

Parameters​
TypeNameDescription
System.UInt64idThe id of the sticker to get.
Discord.CacheModemodeWhether or not to allow downloading from the api.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

GetSticker(UInt64)​

Gets a sticker.

View Source​
Declaration
public SocketSticker GetSticker(ulong id)
Returns​

Discord.WebSocket.SocketSticker: A sticker if found, otherwise null.

Parameters​
TypeNameDescription
System.UInt64idThe unique identifier of the sticker.

GetVoiceRegionsAsync(RequestOptions)​

Gets all voice regions.

View Source​
Declaration
public override async ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
Returns​

System.Threading.Tasks.ValueTask<System.Collections.Generic.IReadOnlyCollection<Discord.Rest.RestVoiceRegion>>: A task that contains a read-only collection of REST-based voice regions.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

GetVoiceRegionAsync(String, RequestOptions)​

Gets a voice region.

View Source​
Declaration
public override async ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
Returns​

System.Threading.Tasks.ValueTask<Discord.Rest.RestVoiceRegion>: A task that contains a REST-based voice region associated with the identifier; null if the voice region is not found.

Parameters​
TypeNameDescription
System.StringidThe identifier of the voice region (e.g. eu-central ).
Discord.RequestOptionsoptionsThe options to be used when sending the request.

DownloadUsersAsync(IEnumerable<IGuild>)​

Attempts to download users into the user cache for the selected guilds.

View Source​
Declaration
public override async Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous download operation.

Parameters​
TypeNameDescription
System.Collections.Generic.IEnumerable<Discord.IGuild>guildsThe guilds to download the members from.

SetStatusAsync(UserStatus)​

Sets the current status of the user (e.g. Online, Do not Disturb).

View Source​
Declaration
public override async Task SetStatusAsync(UserStatus status)
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous set operation.

Parameters​
TypeNameDescription
Discord.UserStatusstatusThe new status to be set.

SetGameAsync(String, String, ActivityType)​

Sets the game of the user.

View Source​
Declaration
public override async Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous set operation.

Parameters​
TypeNameDescription
System.StringnameThe name of the game.
System.StringstreamUrlIf streaming, the URL of the stream. Must be a valid Twitch URL.
Discord.ActivityTypetypeThe type of the game.

SetActivityAsync(IActivity)​

Sets the <code data-dev-comment-type="paramref" class="paramref">activity</code> of the logged-in user.

View Source​
Declaration
public override async Task SetActivityAsync(IActivity activity)
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous set operation.

Parameters​
TypeNameDescription
Discord.IActivityactivityThe activity to be set.

IDiscordClient.GetApplicationInfoAsync(RequestOptions)​

Gets a Discord application information for the logged-in user.

View Source​
Declaration
async Task<IApplication> IDiscordClient.GetApplicationInfoAsync(RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IApplication>: A task that represents the asynchronous get operation. The task result contains the application information.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetChannelAsync(UInt64, CacheMode, RequestOptions)​

Gets a generic channel.

View Source​
Declaration
async Task<IChannel> IDiscordClient.GetChannelAsync(ulong id, CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IChannel>: A task that represents the asynchronous get operation. The task result contains the channel associated with the snowflake identifier; null when the channel cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe snowflake identifier of the channel (e.g. 381889909113225237).
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetPrivateChannelsAsync(CacheMode, RequestOptions)​

Gets a collection of private channels opened in this session.

View Source​
Declaration
Task<IReadOnlyCollection<IPrivateChannel>> IDiscordClient.GetPrivateChannelsAsync(CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IPrivateChannel>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of private channels that the user currently partakes in.

Parameters​
TypeNameDescription
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetDMChannelsAsync(CacheMode, RequestOptions)​

Gets a collection of direct message channels opened in this session.

View Source​
Declaration
Task<IReadOnlyCollection<IDMChannel>> IDiscordClient.GetDMChannelsAsync(CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IDMChannel>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of direct-message channels that the user currently partakes in.

Parameters​
TypeNameDescription
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetGroupChannelsAsync(CacheMode, RequestOptions)​

Gets a collection of group channels opened in this session.

View Source​
Declaration
Task<IReadOnlyCollection<IGroupChannel>> IDiscordClient.GetGroupChannelsAsync(CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IGroupChannel>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of group channels that the user currently partakes in.

Parameters​
TypeNameDescription
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetConnectionsAsync(RequestOptions)​

Gets the connections that the user has set up.

View Source​
Declaration
async Task<IReadOnlyCollection<IConnection>> IDiscordClient.GetConnectionsAsync(RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IConnection>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of connections.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetInviteAsync(String, RequestOptions)​

Gets an invite.

View Source​
Declaration
async Task<IInvite> IDiscordClient.GetInviteAsync(string inviteId, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IInvite>: A task that represents the asynchronous get operation. The task result contains the invite information.

Parameters​
TypeNameDescription
System.StringinviteIdThe invitation identifier.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetGuildAsync(UInt64, CacheMode, RequestOptions)​

Gets a guild.

View Source​
Declaration
Task<IGuild> IDiscordClient.GetGuildAsync(ulong id, CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IGuild>: A task that represents the asynchronous get operation. The task result contains the guild associated with the snowflake identifier; null when the guild cannot be found.

Parameters​
TypeNameDescription
System.UInt64idThe guild snowflake identifier.
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetGuildsAsync(CacheMode, RequestOptions)​

Gets a collection of guilds that the user is currently in.

View Source​
Declaration
Task<IReadOnlyCollection<IGuild>> IDiscordClient.GetGuildsAsync(CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IGuild>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of guilds that the current user is in.

Parameters​
TypeNameDescription
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.CreateGuildAsync(String, IVoiceRegion, Stream, RequestOptions)​

Creates a guild for the logged-in user who is in less than 10 active guilds.

View Source​
Declaration
async Task<IGuild> IDiscordClient.CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IGuild>: A task that represents the asynchronous creation operation. The task result contains the created guild.

Parameters​
TypeNameDescription
System.StringnameThe name of the new guild.
Discord.IVoiceRegionregionThe voice region to create the guild with.
System.IO.StreamjpegIconThe icon of the guild.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetUserAsync(UInt64, CacheMode, RequestOptions)​

Gets a user.

View Source​
Declaration
async Task<IUser> IDiscordClient.GetUserAsync(ulong id, CacheMode mode, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IUser>: A task that represents the asynchronous get operation. The task result contains the user associated with the snowflake identifier; null if the user is not found.

Parameters​
TypeNameDescription
System.UInt64idThe snowflake identifier of the user (e.g. 168693960628371456).
Discord.CacheModemodeThe Discord.CacheMode that determines whether the object should be fetched from cache.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetUserAsync(String, String, RequestOptions)​

Gets a user.

View Source​
Declaration
Task<IUser> IDiscordClient.GetUserAsync(string username, string discriminator, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IUser>: A task that represents the asynchronous get operation. The task result contains the user associated with the name and the discriminator; null if the user is not found.

Parameters​
TypeNameDescription
System.StringusernameThe name of the user (e.g. Still).
System.StringdiscriminatorThe discriminator value of the user (e.g. 2876).
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetVoiceRegionsAsync(RequestOptions)​

Gets a collection of the available voice regions.

View Source​
Declaration
async Task<IReadOnlyCollection<IVoiceRegion>> IDiscordClient.GetVoiceRegionsAsync(RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IVoiceRegion>>: A task that represents the asynchronous get operation. The task result contains a read-only collection with all of the available voice regions in this session.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetVoiceRegionAsync(String, RequestOptions)​

Gets a voice region.

View Source​
Declaration
async Task<IVoiceRegion> IDiscordClient.GetVoiceRegionAsync(string id, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IVoiceRegion>: A task that represents the asynchronous get operation. The task result contains the voice region associated with the identifier; null if the voice region is not found.

Parameters​
TypeNameDescription
System.StringidThe identifier of the voice region (e.g. eu-central ).
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetGlobalApplicationCommandAsync(UInt64, RequestOptions)​

Gets a global application command.

View Source​
Declaration
async Task<IApplicationCommand> IDiscordClient.GetGlobalApplicationCommandAsync(ulong id, RequestOptions options)
Returns​

System.Threading.Tasks.Task<Discord.IApplicationCommand>: A task that represents the asynchronous get operation. The task result contains the application command if found, otherwise null.

Parameters​
TypeNameDescription
System.UInt64idThe id of the command.
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions)​

Gets a collection of all global commands.

View Source​
Declaration
async Task<IReadOnlyCollection<IApplicationCommand>> IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions options)
Returns​

System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.IApplicationCommand>>: A task that represents the asynchronous get operation. The task result contains a read-only collection of global application commands.

Parameters​
TypeNameDescription
Discord.RequestOptionsoptionsThe options to be used when sending the request.

IDiscordClient.StartAsync()​

Starts the connection between Discord and the client..

View Source​
Declaration
async Task IDiscordClient.StartAsync()
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous start operation.

IDiscordClient.StopAsync()​

Stops the connection between Discord and the client.

View Source​
Declaration
async Task IDiscordClient.StopAsync()
Returns​

System.Threading.Tasks.Task: A task that represents the asynchronous stop operation.

Events​

Connected​

Fired when connected to the Discord gateway.

View Source​
Declaration
public event Func<Task> Connected
Event Type​

System.Func<System.Threading.Tasks.Task>

Disconnected​

Fired when disconnected to the Discord gateway.

View Source​
Declaration
public event Func<Exception, Task> Disconnected
Event Type​

System.Func<System.Exception,System.Threading.Tasks.Task>

Ready​

Fired when guild data has finished downloading.

View Source​
Declaration
public event Func<Task> Ready
Event Type​

System.Func<System.Threading.Tasks.Task>

LatencyUpdated​

Fired when a heartbeat is received from the Discord gateway.

View Source​
Declaration
public event Func<int, int, Task> LatencyUpdated
Event Type​

System.Func<System.Int32,System.Int32,System.Threading.Tasks.Task>

Implements​