Class DiscordShardedClient
public class DiscordShardedClient : BaseSocketClient, IRestClientProvider, IDiscordClient, IDisposable, IAsyncDisposable
- Inheritance
-
DiscordShardedClient
- Implements
- Inherited Members
- Extension Methods
Constructors
DiscordShardedClient()
Creates a new REST/WebSocket Discord client.
public DiscordShardedClient()
DiscordShardedClient(DiscordSocketConfig)
Creates a new REST/WebSocket Discord client.
public DiscordShardedClient(DiscordSocketConfig config)
Parameters
config
DiscordSocketConfig
DiscordShardedClient(int[])
Creates a new REST/WebSocket Discord client.
public DiscordShardedClient(int[] ids)
Parameters
ids
int[]
DiscordShardedClient(int[], DiscordSocketConfig)
Creates a new REST/WebSocket Discord client.
public DiscordShardedClient(int[] ids, DiscordSocketConfig config)
Parameters
ids
int[]config
DiscordSocketConfig
Properties
Activity
Gets the activity for the logged-in user.
public override IActivity Activity { get; protected set; }
Property Value
- IActivity
An activity object that represents the user's current activity.
CurrentUser
Gets the current logged-in user.
public override SocketSelfUser CurrentUser { get; protected set; }
Property Value
DefaultStickerPacks
Gets a collection of default stickers.
public override IReadOnlyCollection<StickerPack<SocketSticker>> DefaultStickerPacks { get; }
Property Value
Guilds
Gets a collection of guilds that the user is currently in.
public override IReadOnlyCollection<SocketGuild> Guilds { get; }
Property Value
- IReadOnlyCollection<SocketGuild>
A read-only collection of guilds that the current user is in.
Latency
Gets the estimated round-trip latency, in milliseconds, to the gateway server.
public override int Latency { get; protected set; }
Property Value
- int
An int that represents the round-trip latency to the WebSocket server. Please note that this value does not represent a "true" latency for operations such as sending a message.
PrivateChannels
Gets a collection of private channels opened in this session.
public override IReadOnlyCollection<ISocketPrivateChannel> PrivateChannels { get; }
Property Value
- IReadOnlyCollection<ISocketPrivateChannel>
A read-only collection of private channels that the user currently partakes in.
Remarks
This method will retrieve all private channels (including direct-message, group channel and such) that are currently opened in this session.
warning
This method will not return previously opened private channels outside of the current session! If you have just started the client, this may return an empty collection.
Rest
Provides access to a REST-only client with a shared state from this client.
public override DiscordSocketRestClient Rest { get; }
Property Value
Shards
public IReadOnlyCollection<DiscordSocketClient> Shards { get; }
Property Value
Status
Gets the status for the logged-in user.
public override UserStatus Status { get; protected set; }
Property Value
- UserStatus
A status object that represents the user's online presence status.
Methods
BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[], RequestOptions)
public Task<IReadOnlyCollection<SocketApplicationCommand>> BulkOverwriteGlobalApplicationCommandsAsync(ApplicationCommandProperties[] properties, RequestOptions options = null)
Parameters
properties
ApplicationCommandProperties[]options
RequestOptions
Returns
CreateGlobalApplicationCommandAsync(ApplicationCommandProperties, RequestOptions)
public Task<SocketApplicationCommand> CreateGlobalApplicationCommandAsync(ApplicationCommandProperties properties, RequestOptions options = null)
Parameters
properties
ApplicationCommandPropertiesoptions
RequestOptions
Returns
DownloadUsersAsync(IEnumerable<IGuild>)
Attempts to download users into the user cache for the selected guilds.
public override Task DownloadUsersAsync(IEnumerable<IGuild> guilds)
Parameters
guilds
IEnumerable<IGuild>The guilds to download the members from.
Returns
- Task
A task that represents the asynchronous download operation.
Exceptions
- ArgumentNullException
guilds
is null
GetApplicationInfoAsync(RequestOptions)
Gets a Discord application information for the logged-in user.
public override Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)
Parameters
options
RequestOptionsThe options to be used when sending the request.
Returns
- Task<RestApplication>
A task that represents the asynchronous get operation. The task result contains the application information.
Remarks
This method reflects your application information you submitted when creating a Discord application via the Developer Portal.
GetChannel(ulong)
Gets a channel.
public override SocketChannel GetChannel(ulong id)
Parameters
id
ulongThe snowflake identifier of the channel (e.g.
381889909113225237
).
Returns
- SocketChannel
A generic WebSocket-based channel object (voice, text, category, etc.) associated with the identifier; null when the channel cannot be found.
GetGuild(ulong)
Gets a guild.
public override SocketGuild GetGuild(ulong id)
Parameters
id
ulongThe guild snowflake identifier.
Returns
- SocketGuild
A WebSocket-based guild associated with the snowflake identifier; null when the guild cannot be found.
GetShard(int)
public DiscordSocketClient GetShard(int id)
Parameters
id
int
Returns
GetShardFor(IGuild)
public DiscordSocketClient GetShardFor(IGuild guild)
Parameters
guild
IGuild
Returns
GetShardIdFor(IGuild)
public int GetShardIdFor(IGuild guild)
Parameters
guild
IGuild
Returns
GetStickerAsync(ulong, CacheMode, RequestOptions)
Gets a sticker.
public override Task<SocketSticker> GetStickerAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
id
ulongThe id of the sticker to get.
mode
CacheModeWhether or not to allow downloading from the api.
options
RequestOptionsThe options to be used when sending the request.
Returns
- Task<SocketSticker>
A SocketSticker if found, otherwise null.
GetUser(string, string)
Gets a user.
public override SocketUser GetUser(string username, string discriminator = null)
Parameters
Returns
- SocketUser
A generic WebSocket-based user; null when the user cannot be found.
Remarks
This method gets the user present in the WebSocket cache with the given condition.
warning
Sometimes a user may return null due to Discord not sending offline users in large guilds (i.e. guild with 100+ members) actively. To download users on startup and to see more information about this subject, see AlwaysDownloadUsers.
note
This method does not attempt to fetch users that the logged-in user does not have access to (i.e. users who don't share mutual guild(s) with the current user). If you wish to get a user that you do not have access to, consider using the REST implementation of GetUserAsync(ulong, RequestOptions).
GetUser(ulong)
Gets a generic user.
public override SocketUser GetUser(ulong id)
Parameters
id
ulongThe user snowflake ID.
Returns
- SocketUser
A generic WebSocket-based user; null when the user cannot be found.
Remarks
This method gets the user present in the WebSocket cache with the given condition.
warning
Sometimes a user may return null due to Discord not sending offline users in large guilds (i.e. guild with 100+ members) actively. To download users on startup and to see more information about this subject, see AlwaysDownloadUsers.
note
This method does not attempt to fetch users that the logged-in user does not have access to (i.e. users who don't share mutual guild(s) with the current user). If you wish to get a user that you do not have access to, consider using the REST implementation of GetUserAsync(ulong, RequestOptions).
GetVoiceRegionAsync(string, RequestOptions)
Gets a voice region.
public override ValueTask<RestVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
Parameters
id
stringThe identifier of the voice region (e.g.
eu-central
).options
RequestOptionsThe options to be used when sending the request.
Returns
- ValueTask<RestVoiceRegion>
A task that contains a REST-based voice region associated with the identifier; null if the voice region is not found.
GetVoiceRegionsAsync(RequestOptions)
Gets all voice regions.
public override ValueTask<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
Parameters
options
RequestOptionsThe options to be used when sending the request.
Returns
- ValueTask<IReadOnlyCollection<RestVoiceRegion>>
A task that contains a read-only collection of REST-based voice regions.
SetActivityAsync(IActivity)
Sets the activity
of the logged-in user.
public override Task SetActivityAsync(IActivity activity)
Parameters
activity
IActivityThe activity to be set.
Returns
- Task
A task that represents the asynchronous set operation.
Remarks
This method sets the activity
of the user.
note
Discord will only accept setting of name and the type of activity.
warning
Bot accounts cannot set CustomStatus as their activity type and it will have no effect.
warning
Rich Presence cannot be set via this method or client. Rich Presence is strictly limited to RPC clients only.
SetCustomStatusAsync(string)
Sets the custom status of the logged-in user.
public override Task SetCustomStatusAsync(string status)
Parameters
status
stringThe string that will be displayed as status.
Returns
- Task
A task that represents the asynchronous set operation.
SetGameAsync(string, string, ActivityType)
Sets the game of the user.
public override Task SetGameAsync(string name, string streamUrl = null, ActivityType type = ActivityType.Playing)
Parameters
name
stringThe name of the game.
streamUrl
stringIf streaming, the URL of the stream. Must be a valid Twitch URL.
type
ActivityTypeThe type of the game.
Returns
- Task
A task that represents the asynchronous set operation.
Remarks
warning
Bot accounts cannot set CustomStatus as their activity type and it will have no effect.
SetStatusAsync(UserStatus)
Sets the current status of the user (e.g. Online, Do not Disturb).
public override Task SetStatusAsync(UserStatus status)
Parameters
status
UserStatusThe new status to be set.
Returns
- Task
A task that represents the asynchronous set operation.
StartAsync()
Starts the connection between Discord and the client..
public override Task StartAsync()
Returns
- Task
A task that represents the asynchronous start operation.
Remarks
This method will initialize the connection between the client and Discord.
important
This method will immediately return after it is called, as it will initialize the connection on another thread.
StopAsync()
Stops the connection between Discord and the client.
public override Task StopAsync()
Returns
- Task
A task that represents the asynchronous stop operation.
Events
ShardConnected
Fired when a shard is connected to the Discord gateway.
public event Func<DiscordSocketClient, Task> ShardConnected
Event Type
ShardDisconnected
Fired when a shard is disconnected from the Discord gateway.
public event Func<Exception, DiscordSocketClient, Task> ShardDisconnected
Event Type
ShardLatencyUpdated
Fired when a shard receives a heartbeat from the Discord gateway.
public event Func<int, int, DiscordSocketClient, Task> ShardLatencyUpdated
Event Type
ShardReady
Fired when a guild data for a shard has finished downloading.
public event Func<DiscordSocketClient, Task> ShardReady