Table of Contents

Class DiscordRestClient

Namespace
Discord.Rest
Assembly
Discord.Net.Rest.dll

Provides a client to send REST-based requests to Discord.

public class DiscordRestClient : BaseDiscordClient, IDiscordClient, IDisposable, IAsyncDisposable, IRestClientProvider
Inheritance
DiscordRestClient
Implements
Derived
Inherited Members
Extension Methods

Constructors

DiscordRestClient()

public DiscordRestClient()

DiscordRestClient(DiscordRestConfig)

Initializes a new DiscordRestClient with the provided configuration.

public DiscordRestClient(DiscordRestConfig config)

Parameters

config DiscordRestConfig

The configuration to be used with the client.

Properties

CurrentUser

Gets the logged-in user.

public RestSelfUser CurrentUser { get; }

Property Value

RestSelfUser

Methods

AddReactionAsync(ulong, ulong, IEmote, RequestOptions)

public Task AddReactionAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null)

Parameters

channelId ulong
messageId ulong
emote IEmote
options RequestOptions

Returns

Task

AddRoleAsync(ulong, ulong, ulong, RequestOptions)

public Task AddRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)

Parameters

guildId ulong
userId ulong
roleId ulong
options RequestOptions

Returns

Task

BatchEditGuildCommandPermissions(ulong, IDictionary<ulong, ApplicationCommandPermission[]>, RequestOptions)

public Task<IReadOnlyCollection<GuildApplicationCommandPermission>> BatchEditGuildCommandPermissions(ulong guildId, IDictionary<ulong, ApplicationCommandPermission[]> permissions, RequestOptions options = null)

Parameters

guildId ulong
permissions IDictionary<ulong, ApplicationCommandPermission[]>
options RequestOptions

Returns

Task<IReadOnlyCollection<GuildApplicationCommandPermission>>

BulkOverwriteGlobalCommands(ApplicationCommandProperties[], RequestOptions)

public Task<IReadOnlyCollection<RestGlobalCommand>> BulkOverwriteGlobalCommands(ApplicationCommandProperties[] commandProperties, RequestOptions options = null)

Parameters

commandProperties ApplicationCommandProperties[]
options RequestOptions

Returns

Task<IReadOnlyCollection<RestGlobalCommand>>

BulkOverwriteGuildCommands(ApplicationCommandProperties[], ulong, RequestOptions)

public Task<IReadOnlyCollection<RestGuildCommand>> BulkOverwriteGuildCommands(ApplicationCommandProperties[] commandProperties, ulong guildId, RequestOptions options = null)

Parameters

commandProperties ApplicationCommandProperties[]
guildId ulong
options RequestOptions

Returns

Task<IReadOnlyCollection<RestGuildCommand>>

ConsumeEntitlementAsync(ulong, RequestOptions)

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

public 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.

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

Parameters

name string
image Image
options RequestOptions

Returns

Task<Emote>

CreateGlobalCommand(ApplicationCommandProperties, RequestOptions)

public Task<RestGlobalCommand> CreateGlobalCommand(ApplicationCommandProperties properties, RequestOptions options = null)

Parameters

properties ApplicationCommandProperties
options RequestOptions

Returns

Task<RestGlobalCommand>

CreateGuildAsync(string, IVoiceRegion, Stream, RequestOptions)

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

Parameters

name string
region IVoiceRegion
jpegIcon Stream
options RequestOptions

Returns

Task<RestGuild>

CreateGuildCommand(ApplicationCommandProperties, ulong, RequestOptions)

public Task<RestGuildCommand> CreateGuildCommand(ApplicationCommandProperties properties, ulong guildId, RequestOptions options = null)

Parameters

properties ApplicationCommandProperties
guildId ulong
options RequestOptions

Returns

Task<RestGuildCommand>

CreateTestEntitlementAsync(ulong, ulong, SubscriptionOwnerType, RequestOptions)

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

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

Parameters

skuId ulong
ownerId ulong
ownerType SubscriptionOwnerType
options RequestOptions

Returns

Task<RestEntitlement>

DeleteAllGlobalCommandsAsync(RequestOptions)

public Task DeleteAllGlobalCommandsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task

DeleteApplicationEmoteAsync(ulong, RequestOptions)

Deletes an emote for the current application.

public Task DeleteApplicationEmoteAsync(ulong emoteId, RequestOptions options = null)

Parameters

emoteId ulong
options RequestOptions

Returns

Task

DeleteTestEntitlementAsync(ulong, RequestOptions)

Deletes a currently-active test entitlement.

public Task DeleteTestEntitlementAsync(ulong entitlementId, RequestOptions options = null)

Parameters

entitlementId ulong
options RequestOptions

Returns

Task

GetApplicationEmoteAsync(ulong, RequestOptions)

Gets an emote for the current application.

public 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.

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

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<Emote>>

GetApplicationInfoAsync(RequestOptions)

public Task<RestApplication> GetApplicationInfoAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<RestApplication>

GetChannelAsync(ulong, RequestOptions)

public Task<RestChannel> GetChannelAsync(ulong id, RequestOptions options = null)

Parameters

id ulong
options RequestOptions

Returns

Task<RestChannel>

GetConnectionsAsync(RequestOptions)

public Task<IReadOnlyCollection<RestConnection>> GetConnectionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RestConnection>>

GetCurrentBotInfoAsync(RequestOptions)

public Task<RestApplication> GetCurrentBotInfoAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<RestApplication>

GetCurrentUserAsync(RequestOptions)

public Task<RestSelfUser> GetCurrentUserAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<RestSelfUser>

GetCurrentUserGuildMemberAsync(ulong, RequestOptions)

public Task<RestGuildUser> GetCurrentUserGuildMemberAsync(ulong guildId, RequestOptions options = null)

Parameters

guildId ulong
options RequestOptions

Returns

Task<RestGuildUser>

GetDMChannelsAsync(RequestOptions)

public Task<IReadOnlyCollection<RestDMChannel>> GetDMChannelsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RestDMChannel>>

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

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

public 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>>

GetGlobalApplicationCommands(bool, string, RequestOptions)

public Task<IReadOnlyCollection<RestGlobalCommand>> GetGlobalApplicationCommands(bool withLocalizations = false, string locale = null, RequestOptions options = null)

Parameters

withLocalizations bool
locale string
options RequestOptions

Returns

Task<IReadOnlyCollection<RestGlobalCommand>>

GetGroupChannelsAsync(RequestOptions)

public Task<IReadOnlyCollection<RestGroupChannel>> GetGroupChannelsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RestGroupChannel>>

GetGuildApplicationCommands(ulong, bool, string, RequestOptions)

public Task<IReadOnlyCollection<RestGuildCommand>> GetGuildApplicationCommands(ulong guildId, bool withLocalizations = false, string locale = null, RequestOptions options = null)

Parameters

guildId ulong
withLocalizations bool
locale string
options RequestOptions

Returns

Task<IReadOnlyCollection<RestGuildCommand>>

GetGuildAsync(ulong, RequestOptions)

public Task<RestGuild> GetGuildAsync(ulong id, RequestOptions options = null)

Parameters

id ulong
options RequestOptions

Returns

Task<RestGuild>

GetGuildAsync(ulong, bool, RequestOptions)

public Task<RestGuild> GetGuildAsync(ulong id, bool withCounts, RequestOptions options = null)

Parameters

id ulong
withCounts bool
options RequestOptions

Returns

Task<RestGuild>

GetGuildSummariesAsync(RequestOptions)

public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>>

GetGuildSummariesAsync(ulong, int, RequestOptions)

public IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>> GetGuildSummariesAsync(ulong fromGuildId, int limit, RequestOptions options = null)

Parameters

fromGuildId ulong
limit int
options RequestOptions

Returns

IAsyncEnumerable<IReadOnlyCollection<RestUserGuild>>

GetGuildUserAsync(ulong, ulong, RequestOptions)

public Task<RestGuildUser> GetGuildUserAsync(ulong guildId, ulong id, RequestOptions options = null)

Parameters

guildId ulong
id ulong
options RequestOptions

Returns

Task<RestGuildUser>

GetGuildWidgetAsync(ulong, RequestOptions)

public Task<RestGuildWidget?> GetGuildWidgetAsync(ulong id, RequestOptions options = null)

Parameters

id ulong
options RequestOptions

Returns

Task<RestGuildWidget?>

GetGuildsAsync(RequestOptions)

public Task<IReadOnlyCollection<RestGuild>> GetGuildsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RestGuild>>

GetGuildsAsync(bool, RequestOptions)

public Task<IReadOnlyCollection<RestGuild>> GetGuildsAsync(bool withCounts, RequestOptions options = null)

Parameters

withCounts bool
options RequestOptions

Returns

Task<IReadOnlyCollection<RestGuild>>

GetInviteAsync(string, RequestOptions, ulong?)

public Task<RestInviteMetadata> GetInviteAsync(string inviteId, RequestOptions options = null, ulong? scheduledEventId = null)

Parameters

inviteId string
options RequestOptions
scheduledEventId ulong?

Returns

Task<RestInviteMetadata>

GetPrivateChannelsAsync(RequestOptions)

public Task<IReadOnlyCollection<IRestPrivateChannel>> GetPrivateChannelsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<IRestPrivateChannel>>

GetRoleConnectionMetadataRecordsAsync(RequestOptions)

public Task<IReadOnlyCollection<RoleConnectionMetadata>> GetRoleConnectionMetadataRecordsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RoleConnectionMetadata>>

GetSKUSubscriptionAsync(ulong, ulong, RequestOptions)

Gets a subscription by its id.

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

Parameters

skuId ulong
subscriptionId ulong
options RequestOptions

Returns

Task<RestSubscription>

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

Returns all subscriptions for a given SKU.

public IAsyncEnumerable<IReadOnlyCollection<RestSubscription>> 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<RestSubscription>>

GetSKUsAsync(RequestOptions)

Returns all SKUs for a given application.

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

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<SKU>>

GetUserApplicationRoleConnectionAsync(ulong, RequestOptions)

public Task<RoleConnection> GetUserApplicationRoleConnectionAsync(ulong applicationId, RequestOptions options = null)

Parameters

applicationId ulong
options RequestOptions

Returns

Task<RoleConnection>

GetUserAsync(ulong, RequestOptions)

public Task<RestUser> GetUserAsync(ulong id, RequestOptions options = null)

Parameters

id ulong
options RequestOptions

Returns

Task<RestUser>

GetVoiceRegionAsync(string, RequestOptions)

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

Parameters

id string
options RequestOptions

Returns

Task<RestVoiceRegion>

GetVoiceRegionsAsync(RequestOptions)

public Task<IReadOnlyCollection<RestVoiceRegion>> GetVoiceRegionsAsync(RequestOptions options = null)

Parameters

options RequestOptions

Returns

Task<IReadOnlyCollection<RestVoiceRegion>>

GetWebhookAsync(ulong, RequestOptions)

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

Parameters

id ulong
options RequestOptions

Returns

Task<RestWebhook>

IsValidHttpInteraction(string, string, string, byte[])

public bool IsValidHttpInteraction(string publicKey, string signature, string timestamp, byte[] body)

Parameters

publicKey string
signature string
timestamp string
body byte[]

Returns

bool

IsValidHttpInteraction(string, string, string, string)

public bool IsValidHttpInteraction(string publicKey, string signature, string timestamp, string body)

Parameters

publicKey string
signature string
timestamp string
body string

Returns

bool

ModifyApplicationEmoteAsync(ulong, Action<ApplicationEmoteProperties>, RequestOptions)

Modifies an emote for the current application.

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

Parameters

emoteId ulong
args Action<ApplicationEmoteProperties>
options RequestOptions

Returns

Task<Emote>

ModifyCurrentBotApplicationAsync(Action<ModifyApplicationProperties>, RequestOptions)

public Task<RestApplication> ModifyCurrentBotApplicationAsync(Action<ModifyApplicationProperties> args, RequestOptions options = null)

Parameters

args Action<ModifyApplicationProperties>
options RequestOptions

Returns

Task<RestApplication>

ModifyRoleConnectionMetadataRecordsAsync(ICollection<RoleConnectionMetadataProperties>, RequestOptions)

public Task<IReadOnlyCollection<RoleConnectionMetadata>> ModifyRoleConnectionMetadataRecordsAsync(ICollection<RoleConnectionMetadataProperties> metadata, RequestOptions options = null)

Parameters

metadata ICollection<RoleConnectionMetadataProperties>
options RequestOptions

Returns

Task<IReadOnlyCollection<RoleConnectionMetadata>>

ModifyUserApplicationRoleConnectionAsync(ulong, RoleConnectionProperties, RequestOptions)

public Task<RoleConnection> ModifyUserApplicationRoleConnectionAsync(ulong applicationId, RoleConnectionProperties roleConnection, RequestOptions options = null)

Parameters

applicationId ulong
roleConnection RoleConnectionProperties
options RequestOptions

Returns

Task<RoleConnection>

ParseHttpInteractionAsync(string, string, string, byte[], Func<InteractionProperties, bool>)

Creates a RestInteraction from a http message.

public Task<RestInteraction> ParseHttpInteractionAsync(string publicKey, string signature, string timestamp, byte[] body, Func<InteractionProperties, bool> doApiCallOnCreation = null)

Parameters

publicKey string

The public key of your application

signature string

The signature sent with the interaction.

timestamp string

The timestamp sent with the interaction.

body byte[]

The body of the http message.

doApiCallOnCreation Func<InteractionProperties, bool>

Returns

Task<RestInteraction>

A RestInteraction that represents the incoming http interaction.

Exceptions

BadSignatureException

Thrown when the signature doesn't match the public key.

ParseHttpInteractionAsync(string, string, string, string, Func<InteractionProperties, bool>)

Creates a RestInteraction from a http message.

public Task<RestInteraction> ParseHttpInteractionAsync(string publicKey, string signature, string timestamp, string body, Func<InteractionProperties, bool> doApiCallOnCreation = null)

Parameters

publicKey string

The public key of your application

signature string

The signature sent with the interaction.

timestamp string

The timestamp sent with the interaction.

body string

The body of the http message.

doApiCallOnCreation Func<InteractionProperties, bool>

Returns

Task<RestInteraction>

A RestInteraction that represents the incoming http interaction.

Exceptions

BadSignatureException

Thrown when the signature doesn't match the public key.

RemoveAllReactionsAsync(ulong, ulong, RequestOptions)

public Task RemoveAllReactionsAsync(ulong channelId, ulong messageId, RequestOptions options = null)

Parameters

channelId ulong
messageId ulong
options RequestOptions

Returns

Task

RemoveAllReactionsForEmoteAsync(ulong, ulong, IEmote, RequestOptions)

public Task RemoveAllReactionsForEmoteAsync(ulong channelId, ulong messageId, IEmote emote, RequestOptions options = null)

Parameters

channelId ulong
messageId ulong
emote IEmote
options RequestOptions

Returns

Task

RemoveReactionAsync(ulong, ulong, ulong, IEmote, RequestOptions)

public Task RemoveReactionAsync(ulong channelId, ulong messageId, ulong userId, IEmote emote, RequestOptions options = null)

Parameters

channelId ulong
messageId ulong
userId ulong
emote IEmote
options RequestOptions

Returns

Task

RemoveRoleAsync(ulong, ulong, ulong, RequestOptions)

public Task RemoveRoleAsync(ulong guildId, ulong userId, ulong roleId, RequestOptions options = null)

Parameters

guildId ulong
userId ulong
roleId ulong
options RequestOptions

Returns

Task