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
CurrentUser
Gets the currently logged-in user.
ISelfUser CurrentUser { get; }
Property Value
TokenType
Gets the token type of the logged-in user.
TokenType TokenType { get; }
Property Value
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
RequestOptionsThe 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
ulongThe id of the entitlement.
options
RequestOptionsThe options to be used when sending the request.
Returns
CreateApplicationEmoteAsync(string, Image, RequestOptions)
Creates an emote for the current application.
Task<Emote> CreateApplicationEmoteAsync(string name, Image image, RequestOptions options = null)
Parameters
name
stringimage
Imageoptions
RequestOptions
Returns
CreateGlobalApplicationCommand(ApplicationCommandProperties, RequestOptions)
Creates a global application command.
Task<IApplicationCommand> CreateGlobalApplicationCommand(ApplicationCommandProperties properties, RequestOptions options = null)
Parameters
properties
ApplicationCommandPropertiesThe properties to use when creating the command.
options
RequestOptionsThe 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
stringThe name of the new guild.
region
IVoiceRegionThe voice region to create the guild with.
jpegIcon
StreamThe icon of the guild.
options
RequestOptionsThe 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
ulongownerId
ulongownerType
SubscriptionOwnerTypeoptions
RequestOptions
Returns
DeleteApplicationEmoteAsync(ulong, RequestOptions)
Deletes an emote for the current application.
Task DeleteApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)
Parameters
emoteId
ulongoptions
RequestOptions
Returns
DeleteTestEntitlementAsync(ulong, RequestOptions)
Deletes a currently-active test entitlement.
Task DeleteTestEntitlementAsync(ulong entitlementId, RequestOptions options = null)
Parameters
entitlementId
ulongoptions
RequestOptions
Returns
GetApplicationEmoteAsync(ulong, RequestOptions)
Gets an emote for the current application.
Task<Emote> GetApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)
Parameters
emoteId
ulongoptions
RequestOptions
Returns
GetApplicationEmotesAsync(RequestOptions)
Gets all emotes for the current application.
Task<IReadOnlyCollection<Emote>> GetApplicationEmotesAsync(RequestOptions options = null)
Parameters
options
RequestOptions
Returns
GetApplicationInfoAsync(RequestOptions)
Gets a Discord application information for the logged-in user.
Task<IApplication> GetApplicationInfoAsync(RequestOptions options = null)
Parameters
options
RequestOptionsThe 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
RequestOptionsThe 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
ulongThe snowflake identifier of the channel (e.g.
381889909113225237
).mode
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
RequestOptionsThe 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
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
intafterId
ulong?beforeId
ulong?excludeEnded
boolguildId
ulong?userId
ulong?skuIds
ulong[]options
RequestOptions
Returns
GetGlobalApplicationCommandAsync(ulong, RequestOptions)
Gets a global application command.
Task<IApplicationCommand> GetGlobalApplicationCommandAsync(ulong id, RequestOptions options = null)
Parameters
id
ulongThe id of the command.
options
RequestOptionsThe 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
boolWhether to include full localization dictionaries in the returned objects, instead of the name localized and description localized fields.
locale
stringThe target locale of the localized name and description fields. Sets
X-Discord-Locale
header, which takes precedence overAccept-Language
.options
RequestOptionsThe 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
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
ulongThe guild snowflake identifier.
mode
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
stringThe invitation identifier.
options
RequestOptionsThe 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
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
RequestOptionsThe 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
ulongsubscriptionId
ulongoptions
RequestOptions
Returns
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
Returns
GetSKUsAsync(RequestOptions)
Returns all SKUs for a given application.
Task<IReadOnlyCollection<SKU>> GetSKUsAsync(RequestOptions options = null)
Parameters
options
RequestOptions
Returns
GetUserAsync(string, string, RequestOptions)
Gets a user.
Task<IUser> GetUserAsync(string username, string discriminator, RequestOptions options = null)
Parameters
username
stringThe name of the user (e.g.
Still
).discriminator
stringThe discriminator value of the user (e.g.
2876
).options
RequestOptionsThe 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
ulongThe snowflake identifier of the user (e.g.
168693960628371456
).mode
CacheModeThe CacheMode that determines whether the object should be fetched from cache.
options
RequestOptionsThe 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
stringThe identifier of the voice region (e.g.
eu-central
).options
RequestOptionsThe 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
RequestOptionsThe 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
ulongThe identifier of the webhook.
options
RequestOptionsThe 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
ulongargs
Action<ApplicationEmoteProperties>options
RequestOptions
Returns
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.