Interface IDiscordClient
Represents a generic Discord client.
Namespace: Discord
Assembly: Discord.Net.Core.dll
Syntax
public interface IDiscordClient : IDisposable, IAsyncDisposable
Properties
| Improve this Doc View SourceConnectionState
Gets the current state of connection.
Declaration
ConnectionState ConnectionState { get; }
Property Value
Type | Description |
---|---|
ConnectionState |
CurrentUser
Gets the currently logged-in user.
Declaration
ISelfUser CurrentUser { get; }
Property Value
Type | Description |
---|---|
ISelfUser |
TokenType
Gets the token type of the logged-in user.
Declaration
TokenType TokenType { get; }
Property Value
Type | Description |
---|---|
TokenType |
Methods
| Improve this Doc View SourceBulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[], RequestOptions)
Bulk overwrites all global application commands.
Declaration
Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
ApplicationCommandProperties[] | properties | A collection of properties to use when creating the commands. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<IApplicationCommand>> | A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created. |
CreateGlobalApplicationCommand(ApplicationCommandProperties, RequestOptions)
Creates a global application command.
Declaration
Task<IApplicationCommand> CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
ApplicationCommandProperties | properties | The properties to use when creating the command. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IApplicationCommand> | A task that represents the asynchronous creation operation. The task result contains the created application command. |
CreateGuildAsync(String, IVoiceRegion, Stream, RequestOptions)
Creates a guild for the logged-in user who is in less than 10 active guilds.
Declaration
Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
String | name | The name of the new guild. |
IVoiceRegion | region | The voice region to create the guild with. |
Stream | jpegIcon | The icon of the guild. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IGuild> | A task that represents the asynchronous creation operation. The task result contains the created guild. |
Remarks
This method creates a new guild on behalf of the logged-in user.
warning
Due to Discord's limitation, this method will only work for users that are in less than 10 guilds.
GetApplicationInfoAsync(RequestOptions)
Gets a Discord application information for the logged-in user.
Declaration
Task<IApplication> GetApplicationInfoAsync(RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IApplication> | 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.
GetBotGatewayAsync(RequestOptions)
Gets the gateway information related to the bot.
Declaration
Task<BotGateway> GetBotGatewayAsync(RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<BotGateway> | A task that represents the asynchronous get operation. The task result contains a BotGateway that represents the gateway information related to the bot. |
GetChannelAsync(UInt64, CacheMode, RequestOptions)
Gets a generic channel.
Declaration
Task<IChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | id | The snowflake identifier of the channel (e.g. |
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<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. |
Examples
var channel = await _client.GetChannelAsync(381889909113225237);
if (channel != null && channel is IMessageChannel msgChannel)
{
await msgChannel.SendMessageAsync($"{msgChannel} is created at {msgChannel.CreatedAt}");
}
|
Improve this Doc
View Source
GetConnectionsAsync(RequestOptions)
Gets the connections that the user has set up.
Declaration
Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<IConnection>> | A task that represents the asynchronous get operation. The task result contains a read-only collection of connections. |
GetDMChannelsAsync(CacheMode, RequestOptions)
Gets a collection of direct message channels opened in this session.
Declaration
Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<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. |
Remarks
This method returns a collection of currently opened direct message channels.
warning
This method will not return previously opened DM channels outside of the current session! If you have just started the client, this may return an empty collection.
GetGlobalApplicationCommandAsync(UInt64, RequestOptions)
Gets a global application command.
Declaration
Task<IApplicationCommand> GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | id | The id of the command. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IApplicationCommand> | A task that represents the asynchronous get operation. The task result contains the application command if found, otherwise null. |
GetGlobalApplicationCommandsAsync(Boolean, String, RequestOptions)
Gets a collection of all global commands.
Declaration
Task<IReadOnlyCollection<IApplicationCommand>> GetGlobalApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
Boolean | withLocalizations | Whether to include full localization dictionaries in the returned objects, instead of the name localized and description localized fields. |
String | locale | The target locale of the localized name and description fields. Sets |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<IApplicationCommand>> | A task that represents the asynchronous get operation. The task result contains a read-only collection of global application commands. |
GetGroupChannelsAsync(CacheMode, RequestOptions)
Gets a collection of group channels opened in this session.
Declaration
Task<IReadOnlyCollection<IGroupChannel>> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<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. |
Remarks
This method returns a collection of currently opened group channels.
warning
This method will not return previously opened group channels outside of the current session! If you have just started the client, this may return an empty collection.
GetGuildAsync(UInt64, CacheMode, RequestOptions)
Gets a guild.
Declaration
Task<IGuild> GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | id | The guild snowflake identifier. |
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<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. |
GetGuildsAsync(CacheMode, RequestOptions)
Gets a collection of guilds that the user is currently in.
Declaration
Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<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. |
GetInviteAsync(String, RequestOptions)
Gets an invite.
Declaration
Task<IInvite> GetInviteAsync(string inviteId, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
String | inviteId | The invitation identifier. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IInvite> | A task that represents the asynchronous get operation. The task result contains the invite information. |
GetPrivateChannelsAsync(CacheMode, RequestOptions)
Gets a collection of private channels opened in this session.
Declaration
Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<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. |
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.
GetRecommendedShardCountAsync(RequestOptions)
Gets the recommended shard count as suggested by Discord.
Declaration
Task<int> GetRecommendedShardCountAsync(RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<Int32> | A task that represents the asynchronous get operation. The task result contains an |
GetUserAsync(String, String, RequestOptions)
Gets a user.
Declaration
Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
String | username | The name of the user (e.g. |
String | discriminator | The discriminator value of the user (e.g. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<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. |
Examples
var user = await _client.GetUserAsync("Still", "2876");
if (user != null)
Console.WriteLine($"{user} is created at {user.CreatedAt}.";
|
Improve this Doc
View Source
GetUserAsync(UInt64, CacheMode, RequestOptions)
Gets a user.
Declaration
Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | id | The snowflake identifier of the user (e.g. |
CacheMode | mode | The CacheMode that determines whether the object should be fetched from cache. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<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. |
Examples
var user = await _client.GetUserAsync(168693960628371456);
if (user != null)
Console.WriteLine($"{user} is created at {user.CreatedAt}.";
|
Improve this Doc
View Source
GetVoiceRegionAsync(String, RequestOptions)
Gets a voice region.
Declaration
Task<IVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
String | id | The identifier of the voice region (e.g. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<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. |
GetVoiceRegionsAsync(RequestOptions)
Gets a collection of the available voice regions.
Declaration
Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IReadOnlyCollection<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. |
Examples
The following example gets the most optimal voice region from the collection.
var regions = await client.GetVoiceRegionsAsync();
var optimalRegion = regions.FirstOrDefault(x => x.IsOptimal);
|
Improve this Doc
View Source
GetWebhookAsync(UInt64, RequestOptions)
Gets a webhook available.
Declaration
Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
UInt64 | id | The identifier of the webhook. |
RequestOptions | options | The options to be used when sending the request. |
Returns
Type | Description |
---|---|
Task<IWebhook> | A task that represents the asynchronous get operation. The task result contains a webhook associated with the identifier; null if the webhook is not found. |
StartAsync()
Starts the connection between Discord and the client..
Declaration
Task StartAsync()
Returns
Type | Description |
---|---|
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.
Declaration
Task StopAsync()
Returns
Type | Description |
---|---|
Task | A task that represents the asynchronous stop operation. |