REST API

REST API

Response

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 to get_channel_message, this value will be a Message.
  • ok::Bool: The state of the request. If true, then it is safe to access val.
  • 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"))
source
Discord.fetchvalFunction.
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.

source

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:

  1. A Client, always.
  2. For cases when we don't yet have the entity to be manipulated (usually create and retrieve), the entity's type. If we do have the entity (update and delete), the entity itself.
  3. The remaining positional arguments supply whatever context is needed to specify the entity. For example, sending a message requires a DiscordChannel parameter.
  4. Keyword arguments follow (usually for create and update).
Discord.createFunction.
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")
source
Discord.retrieveFunction.
retrieve(c::Client, ::Type{T}, args...; kwargs...) -> Future{Response}

Retrieve, get, list, etc.

Examples

Getting the Client's User:

retrieve(c, User)

Getting a Guild's DiscordChannels:

retrieve(c, DiscordChannel, guild)

Getting an Invite to a Guild by code:

retrieve(c, Invite, "abcdef")
source
Discord.updateFunction.
update(c::Client, x::T, args...; kwargs...) -> Future{Response}

Update, edit, modify, etc.

Examples

Editing a Message:

update(c, message; content="foo2")

Modifying a Webhook:

update(c, webhook; name="bar2")

Updating a Role:

update(c, role, guild; permissions=8)
source
Discord.deleteFunction.
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)
source

The full list of types available to be manipulated is:

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

get_guild_audit_log(c::Client, guild::Integer; kwargs...) -> AuditLog

Get a Guild's AuditLog. More details here.

source

Channel

Discord.get_channelFunction.
get_channel(c::Client, channel::Integer) -> DiscordChannel

Get a DiscordChannel.

source
modify_channel(c::Client, channel::Integer; kwargs...) -> DiscordChannel

Modify a DiscordChannel. More details here.

source
delete_channel(c::Client, channel::Integer) -> DiscordChannel

Delete a DiscordChannel.

source
get_channel_messages(c::Client, channel::Integer; kwargs...) -> Vector{Message}

Get a list of Messages from a DiscordChannel. More details here.

source
get_channel_message(c::Client, channel::Integer, message::Integer) -> Message

Get a Message from a DiscordChannel.

source
create_message(c::Client, channel::Integer; kwargs...) -> Message

Send a Message to a DiscordChannel. More details here.

source
create_reaction(c::Client, channel::Integer, message::Integer, emoji::StringOrChar)

React to a Message. If emoji is a custom Emoji, it should be formatted "name:id".

source
delete_own_reaction(c::Client, channel::Integer, message::Integer, emoji::StringOrChar)

Delete the Client user's reaction to a Message.

source
delete_user_reaction(
    c::Client,
    channel::Integer,
    message::Integer,
    emoji::StringOrChar,
    user::Integer,
)

Delete a User's reaction to a Message.

source
Discord.get_reactionsFunction.
get_reactions(
    c::Client,
    channel::Integer,
    message::Integer,
    emoji::StringOrChar,
) -> Vector{User}

Get the Users who reacted to a Message with an Emoji.

source
delete_all_reactions(c::Client, channel::Integer, message::Integer)

Delete all reactions from a Message.

source
Discord.edit_messageFunction.
edit_message(c::Client, channel::Integer, message::Integer; kwargs...) -> Message

Edit a Message. More details here.

source
delete_message(c::Client, channel::Integer, message::Integer)

Delete a Message.

source
bulk_delete_messages(c::Client, channel::Integer; kwargs...)

Delete multiple Messages. More details here.

source
edit_channel_permissions(
    c::Client,
    channel::Integer,
    overwrite::Integer;
    kwargs...,
)

Edit permissions for a DiscordChannel. More details here.

source
get_channel_invites(c::Client, channel::Integer) -> Vector{Invite}

Get the Invites for a DiscordChannel.

source
create_channel_invite(c::Client, channel::Integer; kwargs...) -> Invite

Create an Invite to a DiscordChannel. More details here.

source
delete_channel_permission(c::Client, channel::Integer, overwrite::Integer)

Delete an Overwrite from a DiscordChannel.

source
trigger_typing_indicator(c::Client, channel::Integer)

Trigger the typing indicator in a DiscordChannel.

source
get_pinned_messages(c::Client, channel::Integer) -> Vector{Message}

Get the pinned Messages in a DiscordChannel.

source
add_pinned_channel_message(c::Client, channel::Integer, message::Integer)

Pin a Message in a DiscordChannel.

source
delete_pinned_channel_message(c::Client, channel::Integer, message::Integer)

Unpin a Message from a DiscordChannel.

source

Emoji

list_guild_emojis(c::Client, guild::Integer) -> Vector{Emoji}

Get the Emojis in a Guild.

source
get_guild_emoji(c::Client, guild::Integer, emoji::Integer) -> Emoji

Get an Emoji in a Guild.

source
create_guild_emoji(c::Client, guild::Integer; kwargs...) -> Emoji

Create an Emoji in a Guild. More details here.

source
modify_guild_emoji(c::Client, guild::Integer, emoji::Integer; kwargs...) -> Emoji

Edit an Emoji in a Guild. More details here.

source
delete_guild_emoji(c::Client, guild::Integer, emoji::Integer)

Delete an Emoji from a Guild.

source

Guild

Discord.create_guildFunction.
create_guild(c::Client; kwargs...) -> Guild

Create a Guild. More details here.

source
Discord.get_guildFunction.
get_guild(c::Client, guild::Integer) -> Guild

Get a Guild.

source
Discord.modify_guildFunction.
modify_guild(c::Client, guild::Integer; kwargs...) -> Guild

Edit a Guild. More details here.

source
Discord.delete_guildFunction.
delete_guild(c::Client, guild::Integer)

Delete a Guild.

source
get_guild_channels(c::Client, guild::Integer) -> Vector{DiscordChannel}

Get the DiscordChannels in a Guild.

source
create_guild_channel(c::Client, guild::Integer; kwargs...) -> DiscordChannel

Create a DiscordChannel in a Guild. More details here.

source
modify_guild_channel_positions(c::Client, guild::Integer, positions...)

Modify the positions of DiscordChannels in a Guild. More details here.

source
get_guild_member(c::Client, guild::Integer, user::Integer) -> Member

Get a Member in a Guild.

source
list_guild_members(c::Client, guild::Integer; kwargs...) -> Vector{Member}

Get a list of Members in a Guild. More details here.

source
add_guild_member(c::Client; kwargs...) -> Member

Add a User to a Guild. More details here.

source
modify_guild__member(c::Client, guild::Integer, user::Integer; kwargs...)

Modify a Member in a Guild. More details here.

source
modify_current_user_nick(c::Client, guild::Intger; kwargs...) -> String

Modify the Client user's nickname in a Guild. More details here.

source
add_guild_member_role(c::Client, guild::Integer, user::Integer, role::Integer)

Add a Role to a Member.

source
remove_guild_member_role(c::Client, guild::Integer, user::Integer, role::Integer)

Remove a Role from a Member.

source
remove_guild_member(c::Client, guild::Integer, user::Integer)

Kick a Member from a Guild.

source
get_guild_bans(c::Client, guild::Integer) -> Vector{Ban}

Get a list of Bans in a Guild.

source
Discord.get_guild_banFunction.
get_ban(c::Client, guild::Integer,  user::Integer) -> Ban

Get a Ban in a Guild.

source
create_guild_ban(c::Client, guild::Integer, user::Integer; kwargs...)

Ban a Member from a Guild. More details here.

source
remove_guild_ban(c::Client, guild::Integer, user::Integer)

Unban a User from a Guild.

source
get_guild_roles(c::Client, guild::Integer) -> Vector{Role}

Get a Guild's Roles.

source
create_guild_role(c::Client, guild::Integer; kwargs) -> Role

Create a Role in a Guild. More details here.

source
modify_guild_role_positions(c::Client, guild::Integer, positions...) -> Vector{Role}

Modify the positions of Roles in a Guild. More details here.

source
modify_guild_role(c::Client, guild::Integer, role::Integer; kwargs) -> Role

Modify a Role in a Guild. More details here.

source
delete_guild_role(c::Client, guild::Integer, role::Integer)

Delete a Role from a Guild.

source
get_guild_prune_count(c::Client, guild::Integer; kwargs...) -> Dict

Get the number of Members that would be removed from a Guild in a prune. More details here.

source
begin_guild_prune(c::Client, guild::Integer; kwargs...) -> Dict

Begin pruning Members from a Guild. More details here.

source
get_guild_voice_regions(c::Client, guild::Integer) -> Vector{VoiceRegion}

Get a list of VoiceRegions for the Guild.

source
get_guild_invites(c::Client, guild::Integer) -> Vector{Invite}

Get a list of Invites to a Guild.

source
get_guild_integrations(c::Client, guild::Integer) -> Vector{Integration}

Get a list of Integrations for a Guild.

source
create_guild_integration(c::Client, guild::Integer; kwargs...)

Create/attach an Integration to a Guild. More details here.

source
modify_guild_integration(c::Client, guild::Integer, integration::Integer; kwargs...)

Modify an Integration in a Guild. More details here.

source
delete_guild_integration(c::Client, guild::Integer, integration::Integer)

Delete an Integration from a Guild.

source
sync_guild_integration(c::Client, guild::Integer, integration::Integer)

Sync an Integration in a Guild.

source
get_guild_embed(c::Client, guild::Integer) -> GuildEmbed

Get a Guild's GuildEmbed.

source
modify_guild_embed(c::Client, guild::Integer; kwargs...) -> GuildEmbed

Modify a Guild's GuildEmbed. More details here.

source
get_vanity_url(c::Client, guild::Integer) -> Invite

Get a Guild's vanity URL, if it supports that feature.

source
get_guild_widget_image(c::Client, guild::Integer; kwargs...) -> Vector{UInt8}

Get a Guild's widget image in PNG format. More details here.

source

Invite

Discord.get_inviteFunction.
get_invite(c::Client, invite::AbstractString; kwargs...} -> Invite

Get an Invite to a Guild. More details here.

source
Discord.delete_inviteFunction.
delete_invite(c::Client, invite::AbstractString) -> Invite

Delete an Invite to a Guild.

source

User

get_current_user(c::Client) -> User

Get the Client User.

source
Discord.get_userFunction.
get_user(c::Client, user::Integer) -> User

Get a User.

source
modify_current_user(c::Client; kwargs...) -> User

Modify the Client User. More details here.

source
get_user_guilds(c::Client; kwargs...) -> Vector{Guild}

Get a list of Guilds the Client User is a member of. More details here.

source
Discord.leave_guildFunction.
leave_guild(c::Client, guild::Integer)

Leave a Guild.

source
Discord.create_dmFunction.
create_dm(c::Client; kwargs...) -> DiscordChannel

Create a DM DiscordChannel. More details here.

source

Voice

list_voice_regions(c::Client) -> Vector{VoiceRegion}

Get a list of the VoiceRegions that can be used when creating Guilds.

source

Webhook

create_webhook(c::Client, channel::Integer; kwargs...) -> Webhook

Create a Webhook in a DiscordChannel. More details here.

source
get_channel_webhooks(c::Client, channel::Integer) -> Vector{Webhook}

Get a list of Webhooks in a DiscordChannel.

source
get_guild_webhooks(c::Client, guild::Integer) -> Vector{Webhook}

Get a list of Webhooks in a Guild.

source
Discord.get_webhookFunction.
get_webhook(c::Client, webhook::Integer) -> Webhook

Get a Webhook.

source
get_webhook_with_token(c::Client, webhook::Integer, token::AbstractString) -> Webhook

Get a Webhook with a token.

source
modify_webhook(c::Client, webhook::Integer; kwargs...) -> Webhook

Modify a Webhook. More details here.

source
modify_webhook_with_token(
    c::Client,
    webhook::Integer,
    token::AbstractString;
    kwargs...,
) -> Webhook

Modify a Webhook with a token. More details here.

source
delete_webhook(c::Client, webhook::Integer)

Delete a Webhook.

source
delete_webhook_with_token(c::Client, webhook::Integer, token::AbstractString)

Delete a Webhook with a token.

source
execute_webhook(
    c::Client,
    webhook::Integer,
    token::AbstractString;
    wait::Bool=false,
    kwargs...,
) -> Message

Execute a Webhook. If wait is not set, no Message is returned. More details here.

source
execute_slack_compatible_webhook(
    c::Client,
    webhook::Integer,
    token::AbstractString;
    wait::Bool=true,
    kwargs...,
)

Execute a Slack Webhook. More details here.

source
execute_github_compatible_webhook(
    c::Client,
    webhook::Integer,
    token::AbstractString;
    wait::Bool=true,
    kwargs...,
)

Execute a Github Webhook. More details here.

source