Table of Contents

Interface IDiscordClient

Namespace
Discord
Assembly
Discord.Net.Core.dll

Represents a generic Discord client.

public interface IDiscordClient : IDisposable, IAsyncDisposable
Inherited Members
Extension Methods

Properties

ConnectionState

Gets the current state of connection.

ConnectionState ConnectionState { get; }

Property Value

ConnectionState

CurrentUser

Gets the currently logged-in user.

ISelfUser CurrentUser { get; }

Property Value

ISelfUser

TokenType

Gets the token type of the logged-in user.

TokenType TokenType { get; }

Property Value

TokenType

Methods

BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[], RequestOptions)

Bulk overwrites all global application commands.

Task<IReadOnlyCollection<IApplicationCommand>> BulkOverwriteGlobalApplicationCommand(ApplicationCommandProperties[] properties, RequestOptions options = null)

Parameters

properties ApplicationCommandProperties[]

A collection of properties to use when creating the commands.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IReadOnlyCollection<IApplicationCommand>>

A task that represents the asynchronous creation operation. The task result contains a collection of application commands that were created.

ConsumeEntitlementAsync(ulong, RequestOptions)

Marks a given one-time purchase entitlement for the user as consumed.

Task ConsumeEntitlementAsync(ulong entitlementId, RequestOptions options = null)

Parameters

entitlementId ulong

The id of the entitlement.

options RequestOptions

The options to be used when sending the request.

Returns

Task

CreateApplicationEmoteAsync(string, Image, RequestOptions)

Creates an emote for the current application.

Task<Emote> CreateApplicationEmoteAsync(string name, Image image, RequestOptions options = null)

Parameters

name string
image Image
options RequestOptions

Returns

Task<Emote>

CreateGlobalApplicationCommand(ApplicationCommandProperties, RequestOptions)

Creates a global application command.

Task<IApplicationCommand> CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null)

Parameters

properties ApplicationCommandProperties

The properties to use when creating the command.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IGuild> CreateGuildAsync(string name, IVoiceRegion region, Stream jpegIcon = null, RequestOptions options = null)

Parameters

name string

The name of the new guild.

region IVoiceRegion

The voice region to create the guild with.

jpegIcon Stream

The icon of the guild.

options RequestOptions

The options to be used when sending the request.

Returns

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.

CreateTestEntitlementAsync(ulong, ulong, SubscriptionOwnerType, RequestOptions)

Creates a test entitlement to a given SKU for a given guild or user.

Task<IEntitlement> CreateTestEntitlementAsync(ulong skuId, ulong ownerId, SubscriptionOwnerType ownerType, RequestOptions options = null)

Parameters

skuId ulong
ownerId ulong
ownerType SubscriptionOwnerType
options RequestOptions

Returns

Task<IEntitlement>

DeleteApplicationEmoteAsync(ulong, RequestOptions)

Deletes an emote for the current application.

Task DeleteApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)

Parameters

emoteId ulong
options RequestOptions

Returns

Task

DeleteTestEntitlementAsync(ulong, RequestOptions)

Deletes a currently-active test entitlement.

Task DeleteTestEntitlementAsync(ulong entitlementId, RequestOptions options = null)

Parameters

entitlementId ulong
options RequestOptions

Returns

Task

GetApplicationEmoteAsync(ulong, RequestOptions)

Gets an emote for the current application.

Task<Emote> GetApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)

Parameters

emoteId ulong
options RequestOptions

Returns

Task<Emote>

GetApplicationEmotesAsync(RequestOptions)

Gets all emotes for the current application.

Task<IReadOnlyCollection<Emote>> GetApplicationEmotesAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<Emote>>

GetApplicationInfoAsync(RequestOptions)

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

Task<IApplication> GetApplicationInfoAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<BotGateway> GetBotGatewayAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

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(ulong, CacheMode, RequestOptions)

Gets a generic channel.

Task<IChannel> GetChannelAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

id ulong

The snowflake identifier of the channel (e.g. 381889909113225237).

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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}");
}

GetConnectionsAsync(RequestOptions)

Gets the connections that the user has set up.

Task<IReadOnlyCollection<IConnection>> GetConnectionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IReadOnlyCollection<IDMChannel>> GetDMChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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.

GetEntitlementsAsync(int, ulong?, ulong?, bool, ulong?, ulong?, ulong[], RequestOptions)

Returns all entitlements for a given app, active and expired.

IAsyncEnumerable<IReadOnlyCollection<IEntitlement>> GetEntitlementsAsync(int limit = 100, ulong? afterId = null, ulong? beforeId = null, bool excludeEnded = false, ulong? guildId = null, ulong? userId = null, ulong[] skuIds = null, RequestOptions options = null)

Parameters

limit int
afterId ulong?
beforeId ulong?
excludeEnded bool
guildId ulong?
userId ulong?
skuIds ulong[]
options RequestOptions

Returns

IAsyncEnumerable<IReadOnlyCollection<IEntitlement>>

GetGlobalApplicationCommandAsync(ulong, RequestOptions)

Gets a global application command.

Task<IApplicationCommand> GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

The id of the command.

options RequestOptions

The options to be used when sending the request.

Returns

Task<IApplicationCommand>

A task that represents the asynchronous get operation. The task result contains the application command if found, otherwise null.

GetGlobalApplicationCommandsAsync(bool, string, RequestOptions)

Gets a collection of all global commands.

Task<IReadOnlyCollection<IApplicationCommand>> GetGlobalApplicationCommandsAsync(bool withLocalizations = false, string locale = null, RequestOptions options = null)

Parameters

withLocalizations bool

Whether to include full localization dictionaries in the returned objects, instead of the name localized and description localized fields.

locale string

The target locale of the localized name and description fields. Sets X-Discord-Locale header, which takes precedence over Accept-Language.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IReadOnlyCollection<IGroupChannel>> GetGroupChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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(ulong, CacheMode, RequestOptions)

Gets a guild.

Task<IGuild> GetGuildAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

id ulong

The guild snowflake identifier.

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IReadOnlyCollection<IGuild>> GetGuildsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IInvite> GetInviteAsync(string inviteId, RequestOptions options = null)

Parameters

inviteId string

The invitation identifier.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IReadOnlyCollection<IPrivateChannel>> GetPrivateChannelsAsync(CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<int> GetRecommendedShardCountAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

Task<int>

A task that represents the asynchronous get operation. The task result contains an int that represents the number of shards that should be used with this account.

GetSKUSubscriptionAsync(ulong, ulong, RequestOptions)

Gets a subscription by its id.

Task<ISubscription> GetSKUSubscriptionAsync(ulong skuId, ulong subscriptionId, RequestOptions options = null)

Parameters

skuId ulong
subscriptionId ulong
options RequestOptions

Returns

Task<ISubscription>

GetSKUSubscriptionsAsync(ulong, int, ulong?, ulong?, ulong?, RequestOptions)

Returns all subscriptions for a given SKU.

IAsyncEnumerable<IReadOnlyCollection<ISubscription>> GetSKUSubscriptionsAsync(ulong skuId, int limit = 100, ulong? afterId = null, ulong? beforeId = null, ulong? userId = null, RequestOptions options = null)

Parameters

skuId ulong
limit int
afterId ulong?
beforeId ulong?
userId ulong?
options RequestOptions

Returns

IAsyncEnumerable<IReadOnlyCollection<ISubscription>>

GetSKUsAsync(RequestOptions)

Returns all SKUs for a given application.

Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<SKU>>

GetUserAsync(string, string, RequestOptions)

Gets a user.

Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null)

Parameters

username string

The name of the user (e.g. Still).

discriminator string

The discriminator value of the user (e.g. 2876).

options RequestOptions

The options to be used when sending the request.

Returns

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}.";

GetUserAsync(ulong, CacheMode, RequestOptions)

Gets a user.

Task<IUser> GetUserAsync(ulong id, CacheMode mode = CacheMode.AllowDownload, RequestOptions options = null)

Parameters

id ulong

The snowflake identifier of the user (e.g. 168693960628371456).

mode CacheMode

The CacheMode that determines whether the object should be fetched from cache.

options RequestOptions

The options to be used when sending the request.

Returns

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}.";

GetVoiceRegionAsync(string, RequestOptions)

Gets a voice region.

Task<IVoiceRegion> GetVoiceRegionAsync(string id, RequestOptions options = null)

Parameters

id string

The identifier of the voice region (e.g. eu-central ).

options RequestOptions

The options to be used when sending the request.

Returns

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.

Task<IReadOnlyCollection<IVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

The options to be used when sending the request.

Returns

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);

GetWebhookAsync(ulong, RequestOptions)

Gets a webhook available.

Task<IWebhook> GetWebhookAsync(ulong id, RequestOptions options = null)

Parameters

id ulong

The identifier of the webhook.

options RequestOptions

The options to be used when sending the request.

Returns

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.

ModifyApplicationEmoteAsync(ulong, Action<ApplicationEmoteProperties>, RequestOptions)

Modifies an emote for the current application.

Task<Emote> ModifyApplicationEmoteAsync(ulong emoteId, Action<ApplicationEmoteProperties> args, RequestOptions options = null)

Parameters

emoteId ulong
args Action<ApplicationEmoteProperties>
options RequestOptions

Returns

Task<Emote>

StartAsync()

Starts the connection between Discord and the client..

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.

Task StopAsync()

Returns

Task

A task that represents the asynchronous stop operation.