Skip to content
This repository has been archived by the owner on May 31, 2021. It is now read-only.

Azoy/Sword

Repository files navigation

Sword - A Discord Library for Swift

Swift Version Build Status Tag

Requirements

  1. macOS, Linux, or iOS (no voice for iOS)
  2. Swift 4.0
  3. libsodium (brew update && brew install libsodium)

Adding Sword

In order to add Sword as a dependency, you must first create a Swift executable in a designated folder, like so swift package init --type executable. Then in the newly created Package.swift, open it and add Sword as a dependency

// swift-tools-version: 4.0

import PackageDescription

let package = Package(
    name: "yourswiftexecutablehere",
    dependencies: [
        .package(url: "https://github.com/Azoy/Sword", .upToNextMajor(from: "0.9.0"))
    ],
    targets: [
      .target(
        name: "yourswiftexecutablehere",
        dependencies: ["Sword"]
      )
    ]
)

After that, open Sources/main.swift and remove everything and replace it with the example below.

import Sword

let bot = Sword(token: "Your bot token here")

bot.editStatus(to: "online", playing: "with Sword!")

bot.on(.messageCreate) { data in
  let msg = data as! Message

  if msg.content == "!ping" {
    msg.reply(with: "Pong!")
  }
}

bot.connect()

Running the bot

Build the libraries with swift build, then type swift run

Running the bot in Xcode

To run the bot in Xcode, you first have to compile the libraries with swift build. Then to build the xcode project, type swift package generate-xcodeproj. Finally, type open yourswiftexecutablehere.xcodeproj, look at the top and follow the steps below

Step 1

Step 2

Step 3

Then click the play button!

Links

Documentation - (created with Jazzy)

Join the API Channel to ask questions!