Swiftpack.co - SketchMaster2001/Swiftcord as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by SketchMaster2001.
SketchMaster2001/Swiftcord 0.9.3
Swift wrapper for Discord's API. Maintained fork of Azoy's Sword.
⭐️ 18
🕓 1 week ago
macOS
.package(url: "https://github.com/SketchMaster2001/Swiftcord.git", from: "0.9.3")

Swift Version Tag

Swiftcord - A Discord Library for Swift

Requirements

  1. macOS, Linux, iOS, watchOS, tvOS (no voice for iOS, watchOS, or tvOS)
  2. At least Swift 5.3

Adding Sword

Swift Package Manager

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: 5.3

import PackageDescription

let package = Package(
    name: "yourswiftexecutablehere",
    dependencies: [
        .package(url: "https://github.com/SketchMaster2001/Swiftcord", .branch("master"))
    ],
    targets: [
      .target(
        name: "yourswiftexecutablehere",
        dependencies: ["Swiftcord"]
      )
    ]
)

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

import Swiftcord

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

// Set activity if wanted
let activity = Activities(name: "with Swiftcord!", type: .playing)
bot.editStatus(status: .online, activity: activity)

// Set intents which are required
bot.setIntents(intents: .guildMessages)

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

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

bot.connect()

For more examples, look in the examples folder or in the Wiki.

Running the bot (SPM)

First make sure you are in the directory with the Package.swift file. To build the executable, run swift build. To build the executable and run it immediately, run swift run

Running the bot in Xcode (SPM)

To run the bot in Xcode, all you need to do is open the directory the Package.swift file is located in Xcode. Click the play button at the top left corner and it will run!

Then click the play button!

Links

Documentation - Created using Apple docc and converted to HTML with docc2html

Swiftcord Discord server

GitHub

link
Stars: 18
Last commit: 1 week ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

v0.9.3
1 week ago

Swiftcord Release v0.9.3

This release fixes issues that may occur with the web socket connection.

Big thanks to @BennyDeBock and @0xTim!

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics