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.
-
The rate limiter for this consumer.
Declaration
Swift
var rateLimiter: DiscordRateLimiterSpec!
-
addPinnedMessage(_:on:callback:)
Default implementationAdds 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 implementationDeletes 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.
-
createInvite(for:options:reason:callback:)
Default implementationCreates 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 implementationDeletes 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.
-
deleteChannelPermission(_:on:reason:callback:)
Default implementationDeletes 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 implementationDeletes 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 implementationUnpins 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 implementationGets 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 implementationEdits 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.
-
editChannelPermission(_:on:reason:callback:)
Default implementationEdits 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 implementationGets 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
-
getMessages(for:selection:limit:callback:)
Default implementationGets 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
-
modifyChannel(_:options:reason:callback:)
Default implementationModifies 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 implementationGets 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 implementationSends 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 implementationTriggers 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.
-
addGuildMemberRole(_:to:on:reason:callback:)
Default implementationAdds 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.
-
createGuildChannel(on:options:reason:callback:)
Default implementationCreates 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.
-
createGuildRole(on:withOptions:reason:callback:)
Default implementationCreates 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 implementationDeletes 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.
-
getGuildAuditLog(for:withOptions:callback:)
Default implementationGets 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 implementationGets 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 implementationGets 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 implementationGets 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 implementationGets 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
optionscallback
The callback function, taking an array of
DiscordGuildMember
-
getGuildRoles(for:callback:)
Default implementationGets 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
-
guildBan(userId:on:deleteMessageDays:reason:callback:)
Default implementationCreates 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.
-
modifyGuild(_:options:reason:callback:)
Default implementationModifies 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.
-
modifyGuildChannelPositions(on:channelPositions:callback:)
Default implementationModifies 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.
-
modifyGuildMember(_:on:options:reason:callback:)
Default implementationModifies 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.
-
modifyGuildRole(_:on:reason:callback:)
Default implementationEdits 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.
-
removeGuildBan(for:on:reason:callback:)
Default implementationRemoves 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.
-
removeGuildMemberRole(_:from:on:reason:callback:)
Default implementationRemoves 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.
-
removeGuildRole(_:on:reason:callback:)
Default implementationRemoves 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.
-
createWebhook(forChannel:options:reason:callback:)
Default implementationCreates 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 implementationDeletes 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 implementationGets 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 implementationGets 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
DiscordWebhook
s -
getWebhooks(forGuild:callback:)
Default implementationGets 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
DiscordWebhook
s -
modifyWebhook(_:options:reason:callback:)
Default implementationModifies 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 implementationAccepts 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 implementationDeletes 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 implementationGets 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 implementationCreates 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 implementationGets 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 implementationGets 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 implementationCreates 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