Class DiscordSocketClient
Represents a WebSocket-based Discord client.
Assembly: Discord.Net.WebSocket.dll​
View Source​
public class DiscordSocketClient : BaseSocketClient, IDiscordClient, IDisposable
Properties​
Rest​
Provides access to a REST-only client with a shared state from this client.
View Source​
public override DiscordSocketRestClient Rest { get; }
ShardId​
Gets the shard of this client.
View Source​
public int ShardId { get; }
ConnectionState​
Gets the current connection state of this client.
View Source​
public ConnectionState ConnectionState { get; }
Latency​
Gets the estimated round-trip latency, in milliseconds, to the gateway server.
View Source​
public override int Latency { get; protected set; }
Status​
Gets the status for the logged-in user.
View Source​
public override UserStatus Status { get; protected set; }
Activity​
Gets the activity for the logged-in user.
View Source​
public override IActivity Activity { get; protected set; }
Guilds​
Gets a collection of guilds that the user is currently in.
View Source​
public override IReadOnlyCollection<SocketGuild> Guilds { get; }
DefaultStickerPacks​
Gets a collection of default stickers.
View Source​
public override IReadOnlyCollection<StickerPack<SocketSticker>> DefaultStickerPacks { get; }
PrivateChannels​
Gets a collection of private channels opened in this session.
View Source​
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels { get; }
DMChannels​
Gets a collection of direct message channels opened in this session.
View Source​
public IReadOnlyCollection<SocketDMChannel> DMChannels { get; }
GroupChannels​
Gets a collection of group channels opened in this session.
View Source​
public IReadOnlyCollection<SocketGroupChannel> GroupChannels { get; }
Methods​
StartAsync()​
Starts the connection between Discord and the client..
View Source​
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​
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​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
GetGuild(UInt64)​
Gets a guild.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The guild snowflake identifier. |
GetChannel(UInt64)​
Gets a channel.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The 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​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The snowflake identifier of the channel (e.g. 381889909113225237 ). |
Discord.RequestOptions | options | The 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​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The snowflake identifier of the user (e.g. 168693960628371456 ). |
Discord.RequestOptions | options | The options to be used when sending the request. |
PurgeChannelCache()​
Clears all cached channels from the client.
View Source​
public void PurgeChannelCache()
PurgeDMChannelCache()​
Clears cached DM channels from the client.
View Source​
public void PurgeDMChannelCache()
GetUser(UInt64)​
Gets a generic user.
View Source​
public override SocketUser GetUser(ulong id)
Returns​
Discord.WebSocket.SocketUser:
A generic WebSocket-based user; null
when the user cannot be found.
Parameters​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The user snowflake ID. |
GetUser(String, String)​
Gets a user.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | username | The name of the user. |
System.String | discriminator | The discriminator value of the user. |
GetGlobalApplicationCommandAsync(UInt64, RequestOptions)​
Gets a global application command.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The id of the command. |
Discord.RequestOptions | options | The options to be used when sending the request. |
GetGlobalApplicationCommandsAsync(RequestOptions)​
Gets a collection of all global commands.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
CreateGlobalApplicationCommandAsync(ApplicationCommandProperties, RequestOptions)​
View Source​
public async Task<SocketApplicationCommand> CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
Returns​
System.Threading.Tasks.Task<Discord.WebSocket.SocketApplicationCommand>
Parameters​
Type | Name |
---|---|
Discord.ApplicationCommandProperties | properties |
Discord.RequestOptions | options |
BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[], RequestOptions)​
View Source​
public async Task<IReadOnlyCollection<SocketApplicationCommand>> BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[] properties, RequestOptions options = null)
Returns​
System.Threading.Tasks.Task<System.Collections.Generic.IReadOnlyCollection<Discord.WebSocket.SocketApplicationCommand>>
Parameters​
Type | Name |
---|---|
Discord.ApplicationCommandProperties[] | properties |
Discord.RequestOptions | options |
PurgeUserCache()​
Clears cached users from the client.
View Source​
public void PurgeUserCache()
GetStickerAsync(UInt64, CacheMode, RequestOptions)​
Gets a sticker.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The id of the sticker to get. |
Discord.CacheMode | mode | Whether or not to allow downloading from the api. |
Discord.RequestOptions | options | The options to be used when sending the request. |
GetSticker(UInt64)​
Gets a sticker.
View Source​
public SocketSticker GetSticker(ulong id)
Returns​
Discord.WebSocket.SocketSticker: A sticker if found, otherwise null
.
Parameters​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The unique identifier of the sticker. |
GetVoiceRegionsAsync(RequestOptions)​
Gets all voice regions.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
GetVoiceRegionAsync(String, RequestOptions)​
Gets a voice region.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | id | The identifier of the voice region (e.g. eu-central ). |
Discord.RequestOptions | options | The 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​
public override async Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
Returns​
System.Threading.Tasks.Task
:
A task that represents the asynchronous download operation.
Parameters​
Type | Name | Description |
---|---|---|
System.Collections.Generic.IEnumerable<Discord.IGuild> | guilds | The guilds to download the members from. |
SetStatusAsync(UserStatus)​
Sets the current status of the user (e.g. Online, Do not Disturb).
View Source​
public override async Task SetStatusAsync(UserStatus status)
Returns​
System.Threading.Tasks.Task
:
A task that represents the asynchronous set operation.
Parameters​
Type | Name | Description |
---|---|---|
Discord.UserStatus | status | The new status to be set. |
SetGameAsync(String, String, ActivityType)​
Sets the game of the user.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | name | The name of the game. |
System.String | streamUrl | If streaming, the URL of the stream. Must be a valid Twitch URL. |
Discord.ActivityType | type | The 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​
public override async Task SetActivityAsync(IActivity activity)
Returns​
System.Threading.Tasks.Task
:
A task that represents the asynchronous set operation.
Parameters​
Type | Name | Description |
---|---|---|
Discord.IActivity | activity | The activity to be set. |
IDiscordClient.GetApplicationInfoAsync(RequestOptions)​
Gets a Discord application information for the logged-in user.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetChannelAsync(UInt64, CacheMode, RequestOptions)​
Gets a generic channel.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The snowflake identifier of the channel (e.g. 381889909113225237 ). |
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetPrivateChannelsAsync(CacheMode, RequestOptions)​
Gets a collection of private channels opened in this session.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The 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​
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​
Type | Name | Description |
---|---|---|
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetGroupChannelsAsync(CacheMode, RequestOptions)​
Gets a collection of group channels opened in this session.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetConnectionsAsync(RequestOptions)​
Gets the connections that the user has set up.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetInviteAsync(String, RequestOptions)​
Gets an invite.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | inviteId | The invitation identifier. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetGuildAsync(UInt64, CacheMode, RequestOptions)​
Gets a guild.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The guild snowflake identifier. |
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The 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​
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​
Type | Name | Description |
---|---|---|
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The 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​
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​
Type | Name | Description |
---|---|---|
System.String | name | The name of the new guild. |
Discord.IVoiceRegion | region | The voice region to create the guild with. |
System.IO.Stream | jpegIcon | The icon of the guild. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetUserAsync(UInt64, CacheMode, RequestOptions)​
Gets a user.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The snowflake identifier of the user (e.g. 168693960628371456 ). |
Discord.CacheMode | mode | The Discord.CacheMode that determines whether the object should be fetched from cache. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetUserAsync(String, String, RequestOptions)​
Gets a user.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | username | The name of the user (e.g. Still ). |
System.String | discriminator | The discriminator value of the user (e.g. 2876 ). |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetVoiceRegionsAsync(RequestOptions)​
Gets a collection of the available voice regions.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetVoiceRegionAsync(String, RequestOptions)​
Gets a voice region.
View Source​
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​
Type | Name | Description |
---|---|---|
System.String | id | The identifier of the voice region (e.g. eu-central ). |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetGlobalApplicationCommandAsync(UInt64, RequestOptions)​
Gets a global application command.
View Source​
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​
Type | Name | Description |
---|---|---|
System.UInt64 | id | The id of the command. |
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.GetGlobalApplicationCommandsAsync(RequestOptions)​
Gets a collection of all global commands.
View Source​
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​
Type | Name | Description |
---|---|---|
Discord.RequestOptions | options | The options to be used when sending the request. |
IDiscordClient.StartAsync()​
Starts the connection between Discord and the client..
View Source​
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​
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​
public event Func<Task> Connected
Event Type​
System.Func<System.Threading.Tasks.Task>
Disconnected​
Fired when disconnected to the Discord gateway.
View Source​
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​
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​
public event Func<int, int, Task> LatencyUpdated
Event Type​
System.Func<System.Int32,System.Int32,System.Threading.Tasks.Task>
Implements​
- Discord.IDiscordClient
System.IDisposable