Swift wrapper for Discord's API. Maintained fork of Azoy's Sword.

Related tags

Animation Sword
Overview

Sword - A Discord Library for Swift

Swift Version Tag

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/Sword", .branch("master"))
    ],
    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")

// Set activity if wanted
let activity = Activities(name: "with Sword!", 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

The documentation for this repo is out of date due to jazzy not working on my computer. You can still use Azoy's site below to access documentation for pretty much everything except for interactions and message components.

Pre-v9 Documentation - (created with Jazzy)

Comments
  • Add getApplicationCommands() methods, move towards Codable in request()

    Add getApplicationCommands() methods, move towards Codable in request()

    Adds getApplicationCommands() methods to Swiftcord and Guild, to return an array of ApplicationCommand objects which can be inspected. ApplicationCommand objects aren't meant to be used to make new commands, just see what's currently in the global and guild spaces for a bot.

    Also add a parameter to request() and requestWithBodyAsData() and their associated baseRequest...() methods to tell them to return the JSON received from the API as the Data, rather than running it through JSONSerialization and turning it into objects. This is useful for callers who want to just use the straight JSON data to use JSONDecoder to build objects.

    opened by TorgoKong 2
  • Robust-ify SlashCommandBuilder

    Robust-ify SlashCommandBuilder

    Make init methods throwable for ApplicationCommand and other objects it uses, so we can check for property length/size requirements, thus avoiding "Invalid Form Body" errors coming back from the API in these situations. Some other changes regarding Codable conformance of property names (snake-case vs. camel-case).

    opened by TorgoKong 1
  • Add `messageContent` privileged intent

    Add `messageContent` privileged intent

    This new privileged messageContent intent is now required for receiving full content of all messages. Without this, as of September 2022, a bot will receive content of messages only in specific circumstances, such as when you @mention the bot.

    For example, without this, if you just write "Hello everybody!" in a guild, a bot will still receive the event with some related info in it, but the event won't contain "Hello everybody!" anywhere in it since this intent is not enabled.

    related post: https://support-dev.discord.com/hc/en-us/articles/4404772028055

    opened by MahdiBM 0
  • Added addChoices() that takes an array of ApplicationChoices, addRole() and removeRole() functions.

    Added addChoices() that takes an array of ApplicationChoices, addRole() and removeRole() functions.

    Added an addChoices() function to ApplicationCommandOptions that takes a pre-built array of ApplicationChoices, in addition to the variadic form. Added addRole() and removeRole() to Guild to implement those endpoints in the API.

    opened by TorgoKong 0
  • Make InteractionEvent a class-only protocol

    Make InteractionEvent a class-only protocol

    This allows the extension to mutate without needing mutating, allowing calling deferReply and setEpheremal from a ListenerAdapter, which receives classes by reference and not by inout (required to call mutating funcs).

    In short, you can now call deferReply and setEpheremal on arguments in ListenerAdapter as the examples show.

    opened by pontaoski 0
  • Fix evenloop lifecycles issues and add case for normalclosure

    Fix evenloop lifecycles issues and add case for normalclosure

    This PR fixes some eventloop lifecycle issues as well as adding a case for the websocket errorcode normal closure

    Without the handling of that error code, discord would send the code and the bot would stop as discord said it wasn't needed anymore. Now however we try to reconnect on an incoming normal closure request

    opened by BennyDeBock 0
  • Always use `guilds` intent

    Always use `guilds` intent

    We need the guilds intent for caching. If the user doesn't include this intent, many functions are rendered useless. As such we will force the intent.

    opened by noahpistilli 0
  • Fix gateway connection

    Fix gateway connection

    I wouldn't have made this PR, but it is very important. So I didn't realize that url.path didn't include the params needed to connect to the proper API version. As such, it was actually on gateway v6. This PR fixes it and uses EmbedBuilder for sending embeds.

    opened by noahpistilli 0
  • Add Support for the v9 API

    Add Support for the v9 API

    This adds Slash Commands, User Commands, Message Commands, Button and Select Menus, Threads, Guild Scheduled Events, Stage channels and a more in depth Activities setup.

    opened by noahpistilli 0
  • Update getting started code in Readme.md

    Update getting started code in Readme.md

    • Adds a notice because .package(url: String, requirement: Package.Dependency.Requirement) is deprecated in swift 5.5 and up
    • Fixes the code in the onMessageCreate function so that it now compiles
    • The main class example now uses 4 spaces for indention, to be more consistent with the Package.swift example
    opened by Candygoblen123 0
  • Add subcommand support

    Add subcommand support

    Adds subcommand support for slash command To produce a clearer way to handle the subcommand type of option, a refactor to SlashCommandEvent might be needed.

    opened by frank89722 0
  • Add Voice Support

    Add Voice Support

    This PR adds voice support to Swiftcord.

    What works

    • Playing PCM and Opus Audio
    • Basic Gateway support

    Todo

    • Handle Voice Gateway errors
    • Try to add ffmpeg support (I have had insane trouble with it taking too long)
    • Receiving audio
    opened by noahpistilli 0
Releases(0.9.3)
  • 0.9.3(May 9, 2022)

Owner
Sketch
Some kid who likes learning new things, especially about technology
Sketch
Type-safe CAAnimation wrapper. It makes preventing to set wrong type values.

TheAnimation TheAnimation is Type-safe CAAnimation wrapper. Introduction For example, if you want to animate backgroundColor with CABasicAnimation, yo

Taiki Suzuki 222 Dec 6, 2022
LottieView - Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

LottieView is a Wrapper around Lottie in SwiftUI that allows chaining animations & triggering callbacks at certain frames

Ahmed Ramy 0 Jan 23, 2022
A Fast Animation Engine with an Intuitive API

Kinieta An Animation Engine for iOS with an Intuitive API and Readable Code! (Written in Swift 4.0.) Why another? I decided to build an Animation Engi

Michael Michailidis 44 Sep 22, 2022
iOS App using NewsAPI API for International and French retrieval informations

Newsletter iOS App using NewsAPI API for International and French retrieval informations Les Tests Unitaires Logique & UI n'ont pas encore été intégré

null 0 Dec 5, 2021
MediaSearchApp - SwiftUI App using the iTunes Search API

Description iOS App for searching ebooks, movies, and TV shows with the iTunes S

Nneka Udoh 1 Dec 4, 2022
Stagehand provides a modern, type-safe API for building animations on iOS

Stagehand Stagehand provides a modern, type-safe API for building animations on iOS. Stagehand is designed around a set of core ideas: Composition of

Cash App 118 Dec 3, 2022
API to make great custom transitions in one method

AZTransitions Make your modal transition with custom animation. AZTransitions helps you think about creativity, giving specific API methods. Visual Ex

Alexander 418 Aug 4, 2022
☄️Comets: Animating Particles in Swift

Comets ☄️ Comets: Animating Particles in Swift animation made by kevin as part of Voicy design implements Bennet van der Linden medium Comets: Animati

Cruz 593 Dec 28, 2022
A DSL to make animation easy on iOS with Swift.

This project is highly inspired by JHChainableAnimations, If you project is developed with Objective-C, use JHChainableAnimations instead. With DKChai

Draven 1.9k Dec 9, 2022
A Swift library to take the power of UIView.animateWithDuration(_:, animations:...) to a whole new level - layers, springs, chain-able animations and mixing view and layer animations together!

ver 2.0 NB! Breaking changes in 2.0 - due to a lot of requests EasyAnimation does NOT automatically install itself when imported. You need to enable i

Marin Todorov 3k Dec 27, 2022
Elegant SVG animation kit for swift

Elephant This is SVG animation presentation kit for iOS. Example You can run example app. Please open Example-iOS/Elephant-iOS.xcworkspace! Usage You

Kazumasa Shimomura 127 Dec 14, 2022
Gemini is rich scroll based animation framework for iOS, written in Swift.

Overview What is the Gemini? Gemini is rich scroll based animation framework for iOS, written in Swift. You can easily use GeminiCollectionView, which

Shohei Yokoyama 3k Dec 27, 2022
Swift interpolation for gesture-driven animations

Interpolate Interpolate is a powerful Swift interpolation framework for creating interactive gesture-driven animations. Usage The ?? idea of Interpola

Roy Marmelstein 1.8k Dec 20, 2022
Pulse animation for iOS written with Swift.

Pulsator Pulse animation for iOS written with Swift. Great For: Pulses of Bluetooth, BLE, beacons (iBeacon), etc. Map Annotations Installation CocoaPo

Shuichi Tsutsumi 1.3k Jan 6, 2023
A library to simplify iOS animations in Swift.

Updated for Swift 4.2 Requires Xcode 10 and Swift 4.2. Installation Drop in the Spring folder to your Xcode project (make sure to enable "Copy items i

Meng To 14k Jan 3, 2023
Better Easing for SpriteKit in Swift

This easing library began life as a port of buddingmonkey's Objective C SpriteKit Easing library to Swift. This library extends upon the basic easing

Craig Grummitt 110 Dec 17, 2022
Swift library for choreographing animations on the screen.

Spruce iOS Animation Library (and Android) What is it? Spruce is a lightweight animation library that helps choreograph the animations on the screen.

WillowTree, LLC 3.4k Jan 3, 2023
A fantastic Physical animation library for swift

A fantastic Physical animation library for swift(Not Just Spring !!!), it is base on UIDynamic and extension to it, friendly APIs make you use it or c

August 2.9k Jan 4, 2023
A slider widget with a popup bubble displaying the precise value selected written on Swift.

A slider widget with a popup bubble displaying the precise value selected written on Swift. We specialize in the designing and coding of

Ramotion 1.9k Dec 23, 2022