DiscordEndpointConsumer

public protocol DiscordEndpointConsumer

Protocol that declares a type will be a consumer of the Discord REST API. All requests through from a consumer should be rate limited.

This is where a DiscordClient gets the methods that interact with the REST API.

NOTE: Callbacks from the default implementations are NOT executed on the client’s handleQueue. So it is important that if you make modifications to the client inside of a callback, you first dispatch back on the handleQueue.

  • addPinnedMessage(_:on:callback:) Default implementation

    Adds a pinned message.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func addPinnedMessage(_ messageId: MessageID,

    Parameters

    messageId

    The message that is to be pinned’s snowflake id

    on

    The channel that we are adding on

    callback

    An optional callback indicating whether the pinned message was added.

  • bulkDeleteMessages(_:on:callback:) Default implementation

    Deletes a bunch of messages at once.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func bulkDeleteMessages(_ messages: [MessageID],

    Parameters

    messages

    An array of message snowflake ids that are to be deleted

    on

    The channel that we are deleting on

    callback

    An optional callback indicating whether the messages were deleted.

  • Creates an invite for a channelguild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func createInvite(for channelId: ChannelID,

    Parameters

    for

    The channel that we are creating for.

    options

    An array of DiscordEndpointOptions.CreateInvite options.

    reason

    The reason this invite was created.

    callback

    The callback function. Takes an optional DiscordInvite

  • deleteChannel(_:reason:callback:) Default implementation

    Deletes the specified channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteChannel(_ channelId: ChannelID,

    Parameters

    channelId

    The snowflake id of the channel.

    reason

    The reason this channel is being deleted.

    callback

    An optional callback indicating whether the channel was deleted.

  • Deletes a channel permission

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteChannelPermission(_ overwriteId: OverwriteID,

    Parameters

    overwriteId

    The permission overwrite that is to be deleted’s snowflake id.

    on

    The channel that we are deleting on.

    reason

    The reason this overwrite was deleted.

    callback

    An optional callback indicating whether the permission was deleted.

  • deleteMessage(_:on:callback:) Default implementation

    Deletes a single message

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteMessage(_ messageId: MessageID,

    Parameters

    messageId

    The message that is to be deleted’s snowflake id

    on

    The channel that we are deleting on

    callback

    An optional callback indicating whether the message was deleted.

  • deletePinnedMessage(_:on:callback:) Default implementation

    Unpins a message.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deletePinnedMessage(_ messageId: MessageID,

    Parameters

    messageId

    The message that is to be unpinned’s snowflake id

    on

    The channel that we are unpinning on

    callback

    An optional callback indicating whether the message was unpinned.

  • getChannel(_:callback:) Default implementation

    Gets the specified channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getChannel(_ channelId: ChannelID,

    Parameters

    channelId

    The snowflake id of the channel

    callback

    The callback function containing an optional DiscordChannel

  • editMessage(_:on:content:callback:) Default implementation

    Edits a message

    Default Implementation

    Default implementation

    Declaration

    Swift

    func editMessage(_ messageId: MessageID,

    Parameters

    messageId

    The message that is to be edited’s snowflake id

    on

    The channel that we are editing on

    content

    The new content of the message

    callback

    An optional callback containing the edited message, if successful.

  • Edits the specified permission overwrite.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func editChannelPermission(_ permissionOverwrite: DiscordPermissionOverwrite,

    Parameters

    permissionOverwrite

    The new DiscordPermissionOverwrite.

    on

    The channel that we are editing on.

    reason

    The reason this edit was made.

    callback

    An optional callback indicating whether the edit was successful.

  • getInvites(for:callback:) Default implementation

    Gets the invites for a channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getInvites(for channelId: ChannelID,

    Parameters

    for

    The channel that we are getting on

    callback

    The callback function, taking an array of DiscordInvite

  • Gets a group of messages according to the specified options.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getMessages(for channel: ChannelID,

    Parameters

    for

    The channel that we are getting on

    selection

    The selection to use get messages with. A nil value will use Discord’s default, which will get the most recent messages in the channel

    limit

    The maximum number of messages to fetch. Should be in the range 1…100. A nil value will use Discord’s default, which is currently 50.

    callback

    The callback function, taking an array of DiscordMessages

  • Modifies the specified channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyChannel(_ channelId: ChannelID,

    Parameters

    channelId

    The snowflake id of the channel.

    options

    An array of DiscordEndpointOptions.ModifyChannel options.

    reason

    The reason this modification is being made.

    callback

    An optional callback containing the edited guild channel, if successful.

  • getPinnedMessages(for:callback:) Default implementation

    Gets the pinned messages for a channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getPinnedMessages(for channelId: ChannelID,

    Parameters

    for

    The channel that we are getting the pinned messages for

    callback

    The callback function, taking an array of DiscordMessages

  • sendMessage(_:to:callback:) Default implementation

    Sends a message with an optional file and embed to the specified channel.

    Sending just a message:

    client.sendMessage("This is a DiscordMessage", to: channelId, callback: nil)
    

    Sending a message with an embed:

    client.sendMessage(DiscordMessage(content: "This message also comes with an embed", embed: embed),
                       to: channelId, callback: nil)
    

    Sending a fully loaded message:

    client.sendMessage(DiscordMessage(content: "This message has it all", embed: embed, file: file),
                       to: channelId, callback: nil)
    

    Default Implementation

    Default implementation.

    Declaration

    Swift

    func sendMessage(_ message: DiscordMessage,

    Parameters

    message

    The message to send.

    to

    The snowflake id of the channel to send to.

    callback

    An optional callback containing the message, if successful.

  • triggerTyping(on:callback:) Default implementation

    Triggers typing on the specified channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func triggerTyping(on channelId: ChannelID,

    Parameters

    on

    The snowflake id of the channel to send to

    callback

    An optional callback indicating whether typing was triggered.

  • Adds a role to a guild member.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func addGuildMemberRole(_ roleId: RoleID,

    Parameters

    roleId

    The id of the role to add.

    to

    The id of the member to add this role to.

    on

    The id of the guild this member is on.

    reason

    The reason this member is getting this role.

    callback

    An optional callback indicating whether the role was added successfully.

  • Creates a guild channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func createGuildChannel(on guildId: GuildID,

    Parameters

    guildId

    The snowflake id of the guild.

    options

    An array of DiscordEndpointOptions.GuildCreateChannel options.

    reason

    The reason this channel is being created.

    callback

    An optional callback containing the new channel, if successful.

  • Creates a role on a guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func createGuildRole(on guildId: GuildID,

    Parameters

    on

    The snowflake id of the guild.

    withOptions

    The options for the new role. Optional in the default implementation.

    reason

    The reason this role is being created.

    callback

    The callback function, taking an optional DiscordRole.

  • deleteGuild(_:callback:) Default implementation

    Deletes the specified guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteGuild(_ guildId: GuildID,

    Parameters

    guildId

    The snowflake id of the guild

    callback

    An optional callback containing the deleted guild, if successful.

  • Gets a guild’s audit log.

    Default Implementation

    Default implementation.

    Declaration

    Swift

    func getGuildAuditLog(for guildId: GuildID,

    Parameters

    guildId

    The snowflake id of the guild.

    options

    Options for getting the audit log.

    callback

    A callback with the audit log.

  • getGuildBans(for:callback:) Default implementation

    Gets the bans on a guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuildBans(for guildId: GuildID,

    Parameters

    for

    The snowflake id of the guild

    callback

    The callback function, taking an array of DiscordBan

  • getGuildChannels(_:callback:) Default implementation

    Gets the channels on a guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuildChannels(_ guildId: GuildID,

    Parameters

    guildId

    The snowflake id of the guild

    callback

    The callback function, taking an array of DiscordGuildChannel

  • getGuildMember(by:on:callback:) Default implementation

    Gets the specified guild member.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuildMember(by id: UserID,

    Parameters

    by

    The snowflake id of the member

    on

    The snowflake id of the guild

    callback

    The callback function containing an optional DiscordGuildMember

  • getGuildMembers(on:options:callback:) Default implementation

    Gets the members on a guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuildMembers(on guildId: GuildID,

    Parameters

    on

    The snowflake id of the guild

    options

    An array of DiscordEndpointOptions.GuildGetMembers options

    callback

    The callback function, taking an array of DiscordGuildMember

  • getGuildRoles(for:callback:) Default implementation

    Gets the roles on a guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuildRoles(for guildId: GuildID,

    Parameters

    for

    The snowflake id of the guild

    callback

    The callback function, taking an array of DiscordRole

  • Creates a guild ban.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func guildBan(userId: UserID,

    Parameters

    userId

    The snowflake id of the user.

    on

    The snowflake id of the guild.

    deleteMessageDays

    The number of days to delete this user’s messages.

    reason

    The reason for this ban.

    callback

    An optional callback indicating whether the ban was successful.

  • Modifies the specified guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyGuild(_ guildId: GuildID,

    Parameters

    guildId

    The snowflake id of the guild.

    options

    An array of DiscordEndpointOptions.ModifyGuild options.

    reason

    The reason for this modification.

    callback

    An optional callback containing the modified guild, if successful.

  • Modifies the position of a channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyGuildChannelPositions(on guildId: GuildID,

    Parameters

    on

    The snowflake id of the guild

    channelPositions

    An array of channels that should be reordered. Should contain a dictionary in the form ["id": channelId, "position": position]

    callback

    An optional callback containing the modified channels, if successful.

  • Modifies a guild member.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyGuildMember(_ id: UserID,

    Parameters

    id

    The snowflake id of the member.

    on

    The snowflake id of the guild for this member.

    options

    The options for this member.

    reason

    The reason for this change.

    callback

    The callback function, indicating whether the modify succeeded.

  • Edits the specified role.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyGuildRole(_ role: DiscordRole,

    Parameters

    permissionOverwrite

    The new DiscordRole.

    on

    The guild that we are editing on.

    reason

    The reason for this edit.

    callback

    An optional callback containing the modified role, if successful.

  • Removes a guild ban.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func removeGuildBan(for userId: UserID,

    Parameters

    for

    The snowflake id of the user.

    on

    The snowflake id of the guild.

    reason

    The reason for this unban.

    callback

    An optional callback indicating whether the ban was successfully removed.

  • Removes a role from a guild member.

    Default Implementation

    Default implementation.

    Declaration

    Swift

    func removeGuildMemberRole(_ roleId: RoleID,

    Parameters

    roleId

    The id of the role to add.

    from

    The id of the member to add this role to.

    on

    The id of the guild this member is on.

    reason

    The reason for removing this role.

    callback

    An optional callback indicating whether the role was removed successfully.

  • Removes a guild role.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func removeGuildRole(_ roleId: RoleID,

    Parameters

    roleId

    The snowflake id of the role.

    on

    The snowflake id of the guild.

    reason

    The reason for removing this role.

    callback

    An optional callback containing the removed role, if successful.

  • Creates a webhook for a given channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func createWebhook(forChannel channelId: ChannelID,

    Parameters

    forChannel

    The channel to create the webhook for.

    options

    The options for this webhook.

    reason

    The reason this webhook was created.

    callback

    A callback that returns the webhook created, if successful.

  • deleteWebhook(_:reason:callback:) Default implementation

    Deletes a webhook. The user must be the owner of the webhook.

    • paramter callback: An optional callback function that indicates whether the delete was successful.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteWebhook(_ webhookId: WebhookID,

    Parameters

    webhookId

    The id of the webhook.

    reason

    The reason for deleting this webhook.

  • getWebhook(_:callback:) Default implementation

    Gets the specified webhook.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getWebhook(_ webhookId: WebhookID,

    Parameters

    webhookId

    The snowflake id of the webhook.

    callback

    The callback function containing an optional DiscordToken.

  • getWebhooks(forChannel:callback:) Default implementation

    Gets the webhooks for a specified channel.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getWebhooks(forChannel channelId: ChannelID,

    Parameters

    forChannel

    The snowflake id of the channel.

    callback

    The callback function taking an array of DiscordWebhooks

  • getWebhooks(forGuild:callback:) Default implementation

    Gets the webhooks for a specified guild.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getWebhooks(forGuild guildId: GuildID,

    Parameters

    forGuild

    The snowflake id of the guild.

    callback

    The callback function taking an array of DiscordWebhooks

  • Modifies a webhook.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func modifyWebhook(_ webhookId: WebhookID,

    Parameters

    webhookId

    The webhook to modify.

    options

    The options for this webhook.

    reason

    The reason for this modification.

    callback

    A callback that returns the updated webhook, if successful.

  • acceptInvite(_:callback:) Default implementation

    Accepts an invite.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func acceptInvite(_ invite: String,

    Parameters

    invite

    The invite code to accept

    callback

    An optional callback containing the accepted invite, if successful

  • deleteInvite(_:reason:callback:) Default implementation

    Deletes an invite.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func deleteInvite(_ invite: String,

    Parameters

    invite

    The invite code to delete.

    reason

    The reason this invite was deleted.

    callback

    An optional callback containing the deleted invite, if successful.

  • getInvite(_:callback:) Default implementation

    Gets an invite.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getInvite(_ invite: String,

    Parameters

    invite

    The invite code to accept

    callback

    The callback function, takes an optional DiscordInvite

  • createDM(with:callback:) Default implementation

    Creates a direct message channel with a user.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func createDM(with: UserID,

    Parameters

    with

    The user that the channel will be opened with’s snowflake id

    user

    Our snowflake id

    callback

    The callback function. Takes an optional DiscordDMChannel

  • getDMs(callback:) Default implementation

    Gets the direct message channels for a user.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getDMs(callback: @escaping ([ChannelID: DiscordDMChannel], HTTPURLResponse?) -> ())

    Parameters

    user

    Our snowflake id

    callback

    The callback function, taking a dictionary of DiscordDMChannel associated by the recipient’s id

  • getGuilds(callback:) Default implementation

    Gets guilds the user is in.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getGuilds(callback: @escaping ([ChannelID: DiscordUserGuild], HTTPURLResponse?) -> ())

    Parameters

    user

    Our snowflake id

    callback

    The callback function, taking a dictionary of DiscordUserGuild associated by guild id

  • getBotURL(with:) Default implementation

    Creates a url that can be used to authorize a bot.

    Default Implementation

    Default implementation

    Declaration

    Swift

    func getBotURL(with permissions: DiscordPermission) -> URL?

    Parameters

    with

    An array of DiscordPermission that this bot should have