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
messageIdThe message that is to be pinned’s snowflake id
onThe channel that we are adding on
callbackAn 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
messagesAn array of message snowflake ids that are to be deleted
onThe channel that we are deleting on
callbackAn 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
forThe channel that we are creating for.
optionsAn array of
DiscordEndpointOptions.CreateInviteoptions.reasonThe reason this invite was created.
callbackThe 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
channelIdThe snowflake id of the channel.
reasonThe reason this channel is being deleted.
callbackAn 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
overwriteIdThe permission overwrite that is to be deleted’s snowflake id.
onThe channel that we are deleting on.
reasonThe reason this overwrite was deleted.
callbackAn 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
messageIdThe message that is to be deleted’s snowflake id
onThe channel that we are deleting on
callbackAn 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
messageIdThe message that is to be unpinned’s snowflake id
onThe channel that we are unpinning on
callbackAn 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
channelIdThe snowflake id of the channel
callbackThe 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
messageIdThe message that is to be edited’s snowflake id
onThe channel that we are editing on
contentThe new content of the message
callbackAn 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
permissionOverwriteThe new DiscordPermissionOverwrite.
onThe channel that we are editing on.
reasonThe reason this edit was made.
callbackAn 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
forThe channel that we are getting on
callbackThe 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
forThe channel that we are getting on
selectionThe selection to use get messages with. A nil value will use Discord’s default, which will get the most recent messages in the channel
limitThe 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.
callbackThe 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
channelIdThe snowflake id of the channel.
optionsAn array of
DiscordEndpointOptions.ModifyChanneloptions.reasonThe reason this modification is being made.
callbackAn 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
forThe channel that we are getting the pinned messages for
callbackThe 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
messageThe message to send.
toThe snowflake id of the channel to send to.
callbackAn 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
onThe snowflake id of the channel to send to
callbackAn 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
roleIdThe id of the role to add.
toThe id of the member to add this role to.
onThe id of the guild this member is on.
reasonThe reason this member is getting this role.
callbackAn 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
guildIdThe snowflake id of the guild.
optionsAn array of
DiscordEndpointOptions.GuildCreateChanneloptions.reasonThe reason this channel is being created.
callbackAn 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
onThe snowflake id of the guild.
withOptionsThe options for the new role. Optional in the default implementation.
reasonThe reason this role is being created.
callbackThe callback function, taking an optional
DiscordRole. -
deleteGuild(_:callback:)Default implementationDeletes the specified guild.
Default Implementation
Default implementation
Declaration
Swift
func deleteGuild(_ guildId: GuildID,Parameters
guildIdThe snowflake id of the guild
callbackAn 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
guildIdThe snowflake id of the guild.
optionsOptions for getting the audit log.
callbackA 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
forThe snowflake id of the guild
callbackThe 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
guildIdThe snowflake id of the guild
callbackThe 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
byThe snowflake id of the member
onThe snowflake id of the guild
callbackThe 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
onThe snowflake id of the guild
optionsAn array of
DiscordEndpointOptions.GuildGetMembersoptionscallbackThe 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
forThe snowflake id of the guild
callbackThe 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
userIdThe snowflake id of the user.
onThe snowflake id of the guild.
deleteMessageDaysThe number of days to delete this user’s messages.
reasonThe reason for this ban.
callbackAn 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
guildIdThe snowflake id of the guild.
optionsAn array of
DiscordEndpointOptions.ModifyGuildoptions.reasonThe reason for this modification.
callbackAn 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
onThe snowflake id of the guild
channelPositionsAn array of channels that should be reordered. Should contain a dictionary in the form
["id": channelId, "position": position]callbackAn 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
idThe snowflake id of the member.
onThe snowflake id of the guild for this member.
optionsThe options for this member.
reasonThe reason for this change.
callbackThe 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
permissionOverwriteThe new DiscordRole.
onThe guild that we are editing on.
reasonThe reason for this edit.
callbackAn 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
forThe snowflake id of the user.
onThe snowflake id of the guild.
reasonThe reason for this unban.
callbackAn 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
roleIdThe id of the role to add.
fromThe id of the member to add this role to.
onThe id of the guild this member is on.
reasonThe reason for removing this role.
callbackAn 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
roleIdThe snowflake id of the role.
onThe snowflake id of the guild.
reasonThe reason for removing this role.
callbackAn 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
forChannelThe channel to create the webhook for.
optionsThe options for this webhook.
reasonThe reason this webhook was created.
callbackA 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
webhookIdThe id of the webhook.
reasonThe reason for deleting this webhook.
-
getWebhook(_:callback:)Default implementationGets the specified webhook.
Default Implementation
Default implementation
Declaration
Swift
func getWebhook(_ webhookId: WebhookID,Parameters
webhookIdThe snowflake id of the webhook.
callbackThe 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
forChannelThe snowflake id of the channel.
callbackThe callback function taking an array of
DiscordWebhooks -
getWebhooks(forGuild:callback:)Default implementationGets the webhooks for a specified guild.
Default Implementation
Default implementation
Declaration
Swift
func getWebhooks(forGuild guildId: GuildID,Parameters
forGuildThe snowflake id of the guild.
callbackThe callback function taking an array of
DiscordWebhooks -
modifyWebhook(_:options:reason:callback:)Default implementationModifies a webhook.
Default Implementation
Default implementation
Declaration
Swift
func modifyWebhook(_ webhookId: WebhookID,Parameters
webhookIdThe webhook to modify.
optionsThe options for this webhook.
reasonThe reason for this modification.
callbackA 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
inviteThe invite code to accept
callbackAn 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
inviteThe invite code to delete.
reasonThe reason this invite was deleted.
callbackAn 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
inviteThe invite code to accept
callbackThe 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
withThe user that the channel will be opened with’s snowflake id
userOur snowflake id
callbackThe 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
userOur snowflake id
callbackThe callback function, taking a dictionary of
DiscordDMChannelassociated 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
userOur snowflake id
callbackThe callback function, taking a dictionary of
DiscordUserGuildassociated 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
withAn array of
DiscordPermissionthat this bot should have
DiscordEndpointConsumer Protocol Reference