REST API
Response
Discord.Response — Type.A wrapper around a response from the REST API. Every function which wraps a Discord REST API endpoint returns a Future which will contain a value of this type. To retrieve the Response from the Future, use fetch. See also: fetchval.
Fields
val::Nullable{T}: The object contained in the HTTP response. For example, for a call toget_channel_message, this value will be aMessage.ok::Bool: The state of the request. Iftrue, then it is safe to accessval.http_response::Nullable{HTTP.Messages.Response}: The underlying HTTP response, if a request was made.exception::Nullable{Exception}: The caught exception, if one is thrown.
Examples
Multiple API calls which immediately return Futures and can be awaited:
futures = map(i -> create_message(c, channel_id; content=string(i)), 1:10);
other_work_here()
resps = fetch.(futures)Skipping error checks and returning the value directly:
guild = fetchval(create_guild(c; name="foo"))Discord.fetchval — Function.fetchval(f::Future{Response{T}}) -> Nullable{T}Shortcut for fetch(f).val: Fetch a Response and return its value. Note that there are no guarantees about the response's success and the value being returned, and it discards context that can be useful for debugging, such as HTTP responses and caught exceptions.
CRUD API
On top of functions for accessing individual endpoints such as get_channel_messages, Discord.jl also offers a unified API with just four functions. Named after the CRUD model, they cover most of the Discord REST API and allow you to write concise, expressive code, and forget about the subtleties of endpoint naming. The argument ordering convention is roughly as follows:
- A
Client, always. - For cases when we don't yet have the entity to be manipulated (usually
createandretrieve), the entity's type. If we do have the entity (updateanddelete), the entity itself. - The remaining positional arguments supply whatever context is needed to specify the entity. For example, sending a message requires a
DiscordChannelparameter. - Keyword arguments follow (usually for
createandupdate).
Discord.create — Function.create(c::Client, ::Type{T}, args...; kwargs...) -> Future{Response}Create, add, send, etc.
Examples
Sending a Message:
create(c, Message, channel; content="foo")Creating a new DiscordChannel:
create(c, DiscordChannel, guild; name="bar")Banning a Member:
create(c, Ban, guild, member; reason="baz")Discord.retrieve — Function.Discord.update — Function.Discord.delete — Function.delete(c::Client, x::T, args...) -> Future{Response}Delete, remove, discard, etc.
Examples
Kicking a Member:
delete(c, member)Unbanning a Member:
delete(c, ban, guild)Deleting all Reactions from a Message (note: this is the only update/delete method which takes a type parameter):
delete(c, Reaction, message)The full list of types available to be manipulated is:
AuditLogBanDiscordChannelEmojiGuildEmbedGuildIntegrationInviteMemberMessageOverwriteReactionRoleUserVoiceRegionWebhook
Endpoints
Functions which wrap REST API endpoints are named and sorted according to the Discord API documentation. When a function accepts keyword arguments, the docstring will include a link to the Discord documentation which indicates the expected keys and values. Remember that the return types annotated below are not the actual return types, but the types of Response that the returned Futures will yield.
Audit Log
Discord.get_guild_audit_log — Function.Channel
Discord.get_channel — Function.get_channel(c::Client, channel::Integer) -> DiscordChannelGet a DiscordChannel.
Discord.modify_channel — Function.modify_channel(c::Client, channel::Integer; kwargs...) -> DiscordChannelModify a DiscordChannel. More details here.
Discord.delete_channel — Function.delete_channel(c::Client, channel::Integer) -> DiscordChannelDelete a DiscordChannel.
Discord.get_channel_messages — Function.get_channel_messages(c::Client, channel::Integer; kwargs...) -> Vector{Message}Get a list of Messages from a DiscordChannel. More details here.
Discord.get_channel_message — Function.get_channel_message(c::Client, channel::Integer, message::Integer) -> MessageGet a Message from a DiscordChannel.
Discord.create_message — Function.create_message(c::Client, channel::Integer; kwargs...) -> MessageSend a Message to a DiscordChannel. More details here.
Discord.create_reaction — Function.Discord.delete_own_reaction — Function.Discord.delete_user_reaction — Function.Discord.get_reactions — Function.Discord.delete_all_reactions — Function.delete_all_reactions(c::Client, channel::Integer, message::Integer)Delete all reactions from a Message.
Discord.edit_message — Function.Discord.delete_message — Function.delete_message(c::Client, channel::Integer, message::Integer)Delete a Message.
Discord.bulk_delete_messages — Function.Discord.edit_channel_permissions — Function.edit_channel_permissions(
c::Client,
channel::Integer,
overwrite::Integer;
kwargs...,
)Edit permissions for a DiscordChannel. More details here.
Discord.get_channel_invites — Function.get_channel_invites(c::Client, channel::Integer) -> Vector{Invite}Get the Invites for a DiscordChannel.
Discord.create_channel_invite — Function.create_channel_invite(c::Client, channel::Integer; kwargs...) -> InviteCreate an Invite to a DiscordChannel. More details here.
Discord.delete_channel_permission — Function.delete_channel_permission(c::Client, channel::Integer, overwrite::Integer)Delete an Overwrite from a DiscordChannel.
Discord.trigger_typing_indicator — Function.trigger_typing_indicator(c::Client, channel::Integer)Trigger the typing indicator in a DiscordChannel.
Discord.get_pinned_messages — Function.get_pinned_messages(c::Client, channel::Integer) -> Vector{Message}Get the pinned Messages in a DiscordChannel.
Discord.add_pinned_channel_message — Function.add_pinned_channel_message(c::Client, channel::Integer, message::Integer)Pin a Message in a DiscordChannel.
Discord.delete_pinned_channel_message — Function.delete_pinned_channel_message(c::Client, channel::Integer, message::Integer)Unpin a Message from a DiscordChannel.
Emoji
Discord.list_guild_emojis — Function.Discord.get_guild_emoji — Function.Discord.create_guild_emoji — Function.Discord.modify_guild_emoji — Function.Discord.delete_guild_emoji — Function.Guild
Discord.create_guild — Function.Discord.get_guild — Function.get_guild(c::Client, guild::Integer) -> GuildGet a Guild.
Discord.modify_guild — Function.Discord.delete_guild — Function.delete_guild(c::Client, guild::Integer)Delete a Guild.
Discord.get_guild_channels — Function.get_guild_channels(c::Client, guild::Integer) -> Vector{DiscordChannel}Get the DiscordChannels in a Guild.
Discord.create_guild_channel — Function.create_guild_channel(c::Client, guild::Integer; kwargs...) -> DiscordChannelCreate a DiscordChannel in a Guild. More details here.
Discord.modify_guild_channel_positions — Function.modify_guild_channel_positions(c::Client, guild::Integer, positions...)Modify the positions of DiscordChannels in a Guild. More details here.
Discord.get_guild_member — Function.Discord.list_guild_members — Function.Discord.add_guild_member — Function.Discord.modify_guild_member — Function.Discord.modify_current_user_nick — Function.Discord.add_guild_member_role — Function.Discord.remove_guild_member_role — Function.Discord.remove_guild_member — Function.Discord.get_guild_bans — Function.Discord.get_guild_ban — Function.Discord.create_guild_ban — Function.Discord.remove_guild_ban — Function.Discord.get_guild_roles — Function.Discord.create_guild_role — Function.Discord.modify_guild_role_positions — Function.Discord.modify_guild_role — Function.Discord.delete_guild_role — Function.Discord.get_guild_prune_count — Function.Discord.begin_guild_prune — Function.Discord.get_guild_voice_regions — Function.get_guild_voice_regions(c::Client, guild::Integer) -> Vector{VoiceRegion}Get a list of VoiceRegions for the Guild.
Discord.get_guild_invites — Function.Discord.get_guild_integrations — Function.get_guild_integrations(c::Client, guild::Integer) -> Vector{Integration}Get a list of Integrations for a Guild.
Discord.create_guild_integration — Function.create_guild_integration(c::Client, guild::Integer; kwargs...)Create/attach an Integration to a Guild. More details here.
Discord.modify_guild_integration — Function.modify_guild_integration(c::Client, guild::Integer, integration::Integer; kwargs...)Modify an Integration in a Guild. More details here.
Discord.delete_guild_integration — Function.delete_guild_integration(c::Client, guild::Integer, integration::Integer)Delete an Integration from a Guild.
Discord.sync_guild_integration — Function.sync_guild_integration(c::Client, guild::Integer, integration::Integer)Sync an Integration in a Guild.
Discord.get_guild_embed — Function.get_guild_embed(c::Client, guild::Integer) -> GuildEmbedGet a Guild's GuildEmbed.
Discord.modify_guild_embed — Function.modify_guild_embed(c::Client, guild::Integer; kwargs...) -> GuildEmbedModify a Guild's GuildEmbed. More details here.
Discord.get_vanity_url — Function.get_vanity_url(c::Client, guild::Integer) -> InviteGet a Guild's vanity URL, if it supports that feature.
Discord.get_guild_widget_image — Function.Invite
Discord.get_invite — Function.Discord.delete_invite — Function.User
Discord.get_current_user — Function.Discord.get_user — Function.get_user(c::Client, user::Integer) -> UserGet a User.
Discord.modify_current_user — Function.Discord.get_current_user_guilds — Function.Discord.leave_guild — Function.leave_guild(c::Client, guild::Integer)Leave a Guild.
Discord.create_dm — Function.create_dm(c::Client; kwargs...) -> DiscordChannelCreate a DM DiscordChannel. More details here.
Voice
Discord.list_voice_regions — Function.list_voice_regions(c::Client) -> Vector{VoiceRegion}Get a list of the VoiceRegions that can be used when creating Guilds.
Webhook
Discord.create_webhook — Function.create_webhook(c::Client, channel::Integer; kwargs...) -> WebhookCreate a Webhook in a DiscordChannel. More details here.
Discord.get_channel_webhooks — Function.get_channel_webhooks(c::Client, channel::Integer) -> Vector{Webhook}Get a list of Webhooks in a DiscordChannel.
Discord.get_guild_webhooks — Function.Discord.get_webhook — Function.get_webhook(c::Client, webhook::Integer) -> WebhookGet a Webhook.
Discord.get_webhook_with_token — Function.get_webhook_with_token(c::Client, webhook::Integer, token::AbstractString) -> WebhookGet a Webhook with a token.
Discord.modify_webhook — Function.Discord.modify_webhook_with_token — Function.Discord.delete_webhook — Function.delete_webhook(c::Client, webhook::Integer)Delete a Webhook.
Discord.delete_webhook_with_token — Function.delete_webhook_with_token(c::Client, webhook::Integer, token::AbstractString)Delete a Webhook with a token.
Discord.execute_webhook — Function.Discord.execute_slack_compatible_webhook — Function.Discord.execute_github_compatible_webhook — Function.