Sword

open class Sword: Eventable

Main Class for Sword

  • dms

    Collection of DMChannels mapped by user id

    Declaration

    Swift

    public internal(set) var dms = [Snowflake: DM]()
  • Collection of group channels the bot is connected to

    Declaration

    Swift

    public internal(set) var groups = [Snowflake: GroupDM]()
  • Colectionl of guilds the bot is currently connected to

    Declaration

    Swift

    public internal(set) var guilds = [Snowflake: Guild]()
  • Event listeners

    Declaration

    Swift

    public var listeners = [Event: [(Any) -> ()]]()
  • Timestamp of ready event

    Declaration

    Swift

    public internal(set) var readyTimestamp: Date?
  • Amount of shards to initialize

    Declaration

    Swift

    public internal(set) var shardCount = 1
  • Array of unavailable guilds the bot is currently connected to

    Declaration

    Swift

    public internal(set) var unavailableGuilds = [Snowflake: UnavailableGuild]()
  • Int in seconds of how long the bot has been online

    Declaration

    Swift

    public var uptime: Int?
  • The user account for the bot

    Declaration

    Swift

    public internal(set) var user: User?
  • Object of voice connections the bot is currently connected to. Mapped by guildId

    Declaration

    Swift

    public var voiceConnections: [Snowflake: VoiceConnection]
  • Adds a reaction (unicode or custom emoji) to a message

    Declaration

    Swift

    public func addReaction(
        _ reaction: String,
        to messageId: Snowflake,
        in channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Bans a member from a guild

    Option Params

    • delete-message-days: Number of days to delete messages for (0-7)

    Declaration

    Swift

    public func ban(
        _ userId: Snowflake,
        from guildId: Snowflake,
        for reason: String? = nil,
        with options: [String: Any] = [:],
        then completion: ((RequestError?) -> ())? = nil
      )
  • Starts the bot

    Declaration

    Swift

    public func connect()
  • Creates a channel in a guild

    Option Params

    • name: The name to give this channel
    • type: The type of channel to create
    • bitrate: If a voice channel, sets the bitrate for the voice channel
    • user_limit: If a voice channel, sets the maximum amount of users to be allowed at a time
    • permission_overwrites: Array of overwrite objects to give this channel

    Declaration

    Swift

    public func createChannel(
        for guildId: Snowflake,
        with options: [String: Any],
        then completion: ((GuildChannel?, RequestError?) -> ())? = nil
      )
  • Creates a guild

    Declaration

    Swift

    public func createGuild(
        with options: [String: Any],
        then completion: ((Guild?, RequestError?) -> ())? = nil
      )
  • Creates an integration for a guild

    Option Params

    • type: The type of integration to create
    • id: The id of the user’s integration to link to this guild

    Declaration

    Swift

    public func createIntegration(
        for guildId: Snowflake,
        with options: [String: String],
        then completion: ((RequestError?) -> ())? = nil
      )
  • Creates an invite for channel

    Options Params

    • max_age: Duration in seconds before the invite expires, or 0 for never. Default 86400 (24 hours)
    • max_uses: Max number of people who can use this invite, or 0 for unlimited. Default 0
    • temporary: Whether or not this invite gives you temporary access to the guild. Default false
    • unique: Whether or not this invite has a unique invite code. Default false

    Declaration

    Swift

    public func createInvite(
        for channelId: Snowflake,
        with options: [String: Any] = [:],
        then completion: (([String: Any]?, RequestError?) -> ())? = nil
      )
  • Creates a guild role

    Option Params

    • name: The name of the role
    • permissions: The bitwise number to set role with
    • color: Integer value of RGB color
    • hoist: Whether or not this role is hoisted on the member list
    • mentionable: Whether or not this role is mentionable in chat

    Declaration

    Swift

    public func createRole(
        for guildId: Snowflake,
        with options: [String: Any],
        then completion: ((Role?, RequestError?) -> ())? = nil
      )
  • Creates a webhook for a channel

    Options Params

    • name: The name of the webhook
    • avatar: The avatar string to assign this webhook in base64

    Declaration

    Swift

    public func createWebhook(
        for channelId: Snowflake,
        with options: [String: String] = [:],
        then completion: ((Webhook?, RequestError?) -> ())? = nil
      )
  • Deletes a channel

    Declaration

    Swift

    public func deleteChannel(
        _ channelId: Snowflake,
        then completion: ((Channel?, RequestError?) -> ())? = nil
      )
  • Deletes a guild

    Declaration

    Swift

    public func deleteGuild(
        _ guildId: Snowflake,
        then completion: ((Guild?, RequestError?) -> ())? = nil
      )
  • Deletes an integration from a guild

    Declaration

    Swift

    public func deleteIntegration(
        _ integrationId: Snowflake,
        from guildId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Deletes an invite

    Declaration

    Swift

    public func deleteInvite(
        _ inviteId: String,
        then completion: ((Invite?, RequestError?) -> ())? = nil
      )
  • Deletes a message from a channel

    Declaration

    Swift

    public func deleteMessage(
        _ messageId: Snowflake,
        from channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Bulk deletes messages

    Declaration

    Swift

    public func deleteMessages(
        _ messages: [Snowflake],
        from channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Deletes an overwrite permission for a channel

    Declaration

    Swift

    public func deletePermission(
        from channelId: Snowflake,
        with overwriteId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Deletes a reaction from a message by user

    Declaration

    Swift

    public func deleteReaction(
        _ reaction: String,
        from messageId: Snowflake,
        by userId: Snowflake? = nil,
        in channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Deletes all reactions from a message

    Declaration

    Swift

    public func deleteReactions(
        from messageId: Snowflake,
        in channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Deletes a role from this guild

    Declaration

    Swift

    public func deleteRole(
        _ roleId: Snowflake,
        from guildId: Snowflake,
        then completion: ((Role?, RequestError?) -> ())? = nil
      )
  • Deletes a webhook

    Declaration

    Swift

    public func deleteWebhook(
        _ webhookId: Snowflake,
        token: String? = nil,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Disconnects the bot from the gateway

    Declaration

    Swift

    public func disconnect()
  • Edits a message’s content

    Declaration

    Swift

    public func editMessage(
        _ messageId: Snowflake,
        with options: [String: Any],
        in channelId: Snowflake,
        then completion: ((Message?, RequestError?) -> ())? = nil
      )
  • Edits a channel’s overwrite permission

    Option Params

    • allow: The bitwise allowed permissions
    • deny: The bitwise denied permissions
    • type: ‘member’ for a user, or ‘role’ for a role

    Declaration

    Swift

    public func editPermissions(
        _ permissions: [String: Any],
        for channelId: Snowflake,
        with overwriteId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Edits bot status

    Declaration

    Swift

    public func editStatus(to status: String, listening song: String)
  • Edits bot status

    Declaration

    Swift

    public func editStatus(to status: String, playing game: String)
  • Edits bot status

    Game Options

    • name: Name of the game playing/streaming
    • type: 0 for a normal playing game, or 1 for streaming
    • url: Required if streaming, the url discord displays for streams

    Declaration

    Swift

    public func editStatus(to status: String, playing game: [String: Any]? = nil)
  • Edits bot status

    Declaration

    Swift

    public func editStatus(to status: String, watching video: String)
  • Executs a slack style webhook

    Content Params

    Refer to the slack documentation for their webhook structure

    Declaration

    Swift

    public func executeSlackWebhook(
        _ webhookId: Snowflake,
        token webhookToken: String,
        with content: [String: Any],
        then completion: ((RequestError?) -> ())? = nil
      )
  • Executes a webhook

    Content Params

    • content: Message to send
    • username: The username the webhook will send with the message
    • avatar_url: The url of the user the webhook will send
    • tts: Whether or not this message is tts
    • file: The url of the image to send
    • embeds: Array of embed objects to send. Refer to Embed structure

    Declaration

    Swift

    public func executeWebhook(
        _ webhookId: Snowflake,
        token webhookToken: String,
        with content: Any,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Get’s a guild’s audit logs

    Options Params

    • user_id: String of user to look for logs of
    • action_type: Integer of Audit Log Event. Refer to Audit Log Events
    • before: String of entry id to look before
    • limit: Integer of how many entries to return (default 50, minimum 1, maximum 100)

    Declaration

    Swift

    public func getAuditLog(
        from guildId: Snowflake,
        with options: [String: Any]? = nil,
        then completion: @escaping (AuditLog?, RequestError?) -> ()
      )
  • Gets a guild’s bans

    Declaration

    Swift

    public func getBans(
        from guildId: Snowflake,
        then completion: @escaping ([User]?, RequestError?) -> ()
      )
  • Get’s a basic Channel from a ChannelID (NOTE: This tries to get a channel from cache)

    Declaration

    Swift

    public func getChannel(for channelId: Snowflake) -> Channel?
  • Either get a cached channel or restfully get a channel

    Declaration

    Swift

    public func getChannel(
        _ channelId: Snowflake,
        rest: Bool = false,
        then completion: @escaping (Channel?, RequestError?) -> ()
      )
  • Gets a channel’s invites

    Declaration

    Swift

    public func getChannelInvites(
        from channelId: Snowflake,
        then completion: @escaping ([[String: Any]]?, RequestError?) -> ()
      )
  • Either get cached channels from guild

    Declaration

    Swift

    public func getChannels(
        from guildId: Snowflake,
        rest: Bool = false,
        then completion: @escaping ([GuildChannel]?, RequestError?) -> ()
      )
  • Gets the current user’s connections

    Declaration

    Swift

    public func getConnections(
        then completion: @escaping ([[String: Any]]?, RequestError?) -> ()
      )
  • Function to get dm from channelId (NOTE: This tries to get a DM from cache)

    Declaration

    Swift

    public func getDM(for channelId: Snowflake) -> DM?
  • Gets a DM for a user

    Declaration

    Swift

    public func getDM(
        for userId: Snowflake,
        then completion: @escaping (DM?, RequestError?) -> ()
      )
  • Gets the gateway URL to connect to

    Declaration

    Swift

    public func getGateway(
        then completion: @escaping ([String: Any]?, RequestError?) -> ()
      )
  • Function to get guild from channelId

    Declaration

    Swift

    public func getGuild(for channelId: Snowflake) -> Guild?
  • Either get a cached guild or restfully get a guild

    Declaration

    Swift

    public func getGuild(
        _ guildId: Snowflake,
        rest: Bool = false,
        then completion: @escaping (Guild?, RequestError?) -> ()
      )
  • Gets a guild’s embed

    Declaration

    Swift

    public func getGuildEmbed(
        from guildId: Snowflake,
        then completion: @escaping ([String: Any]?, RequestError?) -> ()
      )
  • Gets a guild’s invites

    Declaration

    Swift

    public func getGuildInvites(
        from guildId: Snowflake,
        then completion: @escaping ([[String: Any]]?, RequestError?) -> ()
      )
  • Gets a guild’s webhooks

    Declaration

    Swift

    public func getGuildWebhooks(
        from guildId: Snowflake,
        then completion: @escaping ([Webhook]?, RequestError?) -> ()
      )
  • Gets a guild’s integrations

    Declaration

    Swift

    public func getIntegrations(
        from guildId: Snowflake,
        then completion: @escaping ([[String: Any]]?, RequestError?) -> ()
      )
  • Gets an invite

    Declaration

    Swift

    public func getInvite(
        _ inviteId: String,
        then completion: @escaping ([String: Any]?, RequestError?) -> ()
      )
  • Gets a member from guild

    Declaration

    Swift

    public func getMember(
        _ userId: Snowflake,
        from guildId: Snowflake,
        then completion: @escaping (Member?, RequestError?) -> ()
        )
  • Gets an array of guild members in a guild

    Option Params

    • limit: Amount of members to get (1-1000)
    • after: Message Id of highest member to get members from

    Declaration

    Swift

    public func getMembers(
        from guildId: Snowflake,
        with options: [String: Any]? = nil,
        then completion: @escaping ([Member]?, RequestError?) -> ()
      )
  • Gets a message from channel

    Declaration

    Swift

    public func getMessage(
        _ messageId: Snowflake,
        from channelId: Snowflake,
        then completion: @escaping (Message?, RequestError?) -> ()
      )
  • Gets an array of messages from channel

    Option Params

    • around: Message Id to get messages around
    • before: Message Id to get messages before this one
    • after: Message Id to get messages after this one
    • limit: Number of how many messages you want to get (1-100)

    Declaration

    Swift

    public func getMessages(
        from channelId: Snowflake,
        with options: [String: Any]? = nil,
        then completion: @escaping ([Message]?, RequestError?) -> ()
      )
  • Get pinned messages from a channel

    Declaration

    Swift

    public func getPinnedMessages(
        from channelId: Snowflake,
        then completion: @escaping ([Message]?, RequestError?) -> ()
      )
  • Gets number of users who would be pruned by x amount of days in a guild

    Declaration

    Swift

    public func getPruneCount(
        from guildId: Snowflake,
        for limit: Int,
        then completion: @escaping (Int?, RequestError?) -> ()
      )
  • Gets an array of users who used reaction from message

    Declaration

    Swift

    public func getReaction(
        _ reaction: String,
        from messageId: Snowflake,
        in channelId: Snowflake,
        then completion: @escaping ([User]?, RequestError?) -> ()
      )
  • Gets a guild’s roles

    Declaration

    Swift

    public func getRoles(
        from guildId: Snowflake,
        then completion: @escaping ([Role]?, RequestError?) -> ()
      )
  • Gets shard that is handling a guild

    Declaration

    Swift

    public func getShard(for guildId: Snowflake) -> Int
  • Either get a cached user or restfully get a user

    Declaration

    Swift

    public func getUser(
        _ userId: Snowflake,
        then completion: @escaping (User?, RequestError?) -> ()
      )
  • Get’s the current user’s guilds

    Option Params

    • before: Guild Id to get guilds before this one
    • after: Guild Id to get guilds after this one
    • limit: Amount of guilds to return (1-100)

    Declaration

    Swift

    public func getUserGuilds(
        with options: [String: Any]? = nil,
        then completion: @escaping ([UserGuild]?, RequestError?) -> ()
      )
  • Gets an array of voice regions from a guild

    Declaration

    Swift

    public func getVoiceRegions(
        from guildId: Snowflake,
        then completion: @escaping ([[String: Any]]?, RequestError?) -> ()
      )
  • Gets a webhook

    Declaration

    Swift

    public func getWebhook(
        _ webhookId: Snowflake,
        token: String? = nil,
        then completion: @escaping (Webhook?, RequestError?) -> ()
      )
  • Gets a channel’s webhooks

    Declaration

    Swift

    public func getWebhooks(
        from channelId: Snowflake,
        then completion: @escaping ([Webhook]?, RequestError?) -> ()
      )
  • Joins a voice channel

    Declaration

    Swift

    public func joinVoiceChannel(
        _ channelId: Snowflake,
        then completion: @escaping (VoiceConnection) -> ()
      )
  • Kicks a member from a guild

    Declaration

    Swift

    public func kick(
        _ userId: Snowflake,
        from guildId: Snowflake,
        for reason: String? = nil,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Kills a shard

    Declaration

    Swift

    public func kill(_ id: Int)
  • Leaves a guild

    Declaration

    Swift

    public func leaveGuild(
        _ guildId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Leaves a voice channel

    Declaration

    Swift

    public func leaveVoiceChannel(_ channelId: Snowflake)
  • Modifies a guild channel

    Options Params

    • name: Name to give channel
    • position: Channel position to set it to
    • topic: If a text channel, sets the topic of the text channel
    • bitrate: If a voice channel, sets the bitrate for the voice channel
    • user_limit: If a voice channel, sets the maximum allowed users in a voice channel

    Declaration

    Swift

    public func modifyChannel(
        _ channelId: Snowflake,
        with options: [String: Any] = [:],
        then completion: ((GuildChannel?, RequestError?) -> ())? = nil
      )
  • Modifies channel positions from a guild

    Options Params

    Array of the following:

    • id: The channel id to modify
    • position: The sorting position of the channel

    Declaration

    Swift

    public func modifyChannelPositions(
        for guildId: Snowflake,
        with options: [[String: Any]],
        then completion: (([GuildChannel]?, RequestError?) -> ())? = nil
      )
  • Modifes a Guild Embed

    Options Params

    • enabled: Whether or not embed should be enabled
    • channel_id: Snowflake of embed channel

    Declaration

    Swift

    public func modifyEmbed(
        for guildId: Snowflake,
        with options: [String: Any],
        then completion: (([String: Any]?, RequestError?) -> ())? = nil
      )
  • Modifies a guild

    Options Params

    • name: The name to assign to the guild
    • region: The region to set this guild to
    • verification_level: The guild verification level integer
    • default_message_notifications: The guild default message notification settings integer
    • afk_channel_id: The channel id to assign afks
    • afk_timeout: The amount of time in seconds to afk a user in voice
    • icon: The icon in base64 string
    • owner_id: The user id to make own of this server
    • splash: If a VIP server, the splash image in base64 to assign

    Declaration

    Swift

    public func modifyGuild(
        _ guildId: Snowflake,
        with options: [String: Any],
        then completion: ((Guild?, RequestError?) -> ())? = nil
      )
  • Modifies an integration from a guild

    Option Params

    • expire_behavior: The behavior when an integration subscription lapses (see the integration object documentation)
    • expire_grace_period: Period (in seconds) where the integration will ignore lapsed subscriptions
    • enable_emoticons: Whether emoticons should be synced for this integration (twitch only currently), true or false

    Declaration

    Swift

    public func modifyIntegration(
        _ integrationId: Snowflake,
        for guildId: Snowflake,
        with options: [String: Any],
        then completion: ((RequestError?) -> ())? = nil
      )
  • Modifies a member from a guild

    Options Params

    • nick: The nickname to assign
    • roles: Array of role id’s that should be assigned to the member
    • mute: Whether or not to server mute the member
    • deaf: Whether or not to server deafen the member
    • channel_id: If the user is connected to a voice channel, assigns them the new voice channel they are to connect.

    Declaration

    Swift

    public func modifyMember(
        _ userId: Snowflake,
        in guildId: Snowflake,
        with options: [String: Any],
        then completion: ((RequestError?) -> ())? = nil
      )
  • Modifies a role from a guild

    Options Params

    • name: The name to assign to the role
    • permissions: The bitwise permission integer
    • color: RGB int color value to assign to the role
    • hoist: Whether or not this role should be hoisted on the member list
    • mentionable: Whether or not this role should be mentionable by everyone

    Declaration

    Swift

    public func modifyRole(
        _ roleId: Snowflake,
        for guildId: Snowflake,
        with options: [String: Any],
        then completion: ((Role?, RequestError?) -> ())? = nil
      )
  • Modifies role positions from a guild

    Options Params

    Array of the following:

    • id: The role id to edit position
    • position: The sorting position of the role

    Declaration

    Swift

    public func modifyRolePositions(
        for guildId: Snowflake,
        with options: [[String: Any]],
        then completion: (([Role]?, RequestError?) -> ())? = nil
      )
  • Modifies a webhook

    Option Params

    • name: The name given to the webhook
    • avatar: The avatar image to give webhook in base 64 string

    Declaration

    Swift

    public func modifyWebhook(
        _ webhookId: Snowflake,
        token: String? = nil,
        with options: [String: String],
        then completion: ((Webhook?, RequestError?) -> ())? = nil
      )
  • Moves a member in a voice channel to another voice channel (if they are in one)

    Declaration

    Swift

    public func moveMember(
        _ userId: Snowflake,
        in guildId: Snowflake,
        to channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Pins a message to a channel

    Declaration

    Swift

    public func pin(
        _ messageId: Snowflake,
        in channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Prunes members for x amount of days in a guild

    Declaration

    Swift

    public func pruneMembers(
        in guildId: Snowflake,
        for limit: Int,
        then completion: ((Int?, RequestError?) -> ())? = nil
      )
  • Removes a user from a Group DM

    Declaration

    Swift

    public func removeUser(
        _ userId: Snowflake,
        fromGroupDM groupDMId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Sends a message to channel

    Declaration

    Swift

    public func send(
        _ content: String,
        to channelId: Snowflake,
        then completion: ((Message?, RequestError?) -> ())? = nil
      )
  • Sends a message to channel

    Content Dictionary Params

    • content: Message to send
    • username: The username the webhook will send with the message
    • avatar_url: The url of the user the webhook will send
    • tts: Whether or not this message is tts
    • file: The url of the image to send
    • embed: The embed object to send. Refer to Embed structure

    Declaration

    Swift

    public func send(
        _ content: [String: Any],
        to channelId: Snowflake,
        then completion: ((Message?, RequestError?) -> ())? = nil
      )
  • Sends an embed to channel

    Declaration

    Swift

    public func send(
        _ content: Embed,
        to channelId: Snowflake,
        then completion: ((Message?, RequestError?) -> ())? = nil
      )
  • Sets bot to typing in channel

    Declaration

    Swift

    public func setTyping(
        for channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Sets bot’s username

    Declaration

    Swift

    public func setUsername(
        to name: String,
        then completion: ((User?, RequestError?) -> ())? = nil
      )
  • Used to spawn a shard

    Declaration

    Swift

    public func spawn(_ id: Int)
  • Syncs an integration for a guild

    Declaration

    Swift

    public func syncIntegration(
        _ integrationId: Snowflake,
        for guildId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Unbans a user from this guild

    Declaration

    Swift

    public func unbanMember(
        _ userId: Snowflake,
        from guildId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )
  • Unpins a pinned message from a channel

    Declaration

    Swift

    public func unpin(
        _ messageId: Snowflake,
        from channelId: Snowflake,
        then completion: ((RequestError?) -> ())? = nil
      )