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

Overview

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

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
This package gives wrapper methods for Desk360 SDK.

Desk360 (flutter sdk) This package gives wrapper methods for desk360 sdks. iOS - Android Getting started Add below code into your pubspec.yaml file un

Teknasyon Tech 10 Dec 12, 2022
RadioTimeKit - The Swift SDK for TuneIn RadioTimeKit is a Swift package to use the TuneIn API.

RadioTimeKit - The Swift SDK for TuneIn RadioTimeKit is a Swift package to use the TuneIn API. The goal for development was to have a Swift SDK to get

Frank Gregor 2 Jun 20, 2022
Swift SDK for Blockfrost.io API

Swift5 API client for Blockfrost Swift 5 SDK for Blockfrost.io API. Installation • Usage • API Endpoints Installation Swift package manager dependenci

blockfrost.io 10 Dec 24, 2022
Swift framework for authenticating with the Spotify API

SpotifyLogin SpotifyLogin is a Swift 5 Framework for authenticating with the Spotify API. Usage of this framework is bound under the Developer Terms o

Spotify 344 Jan 4, 2023
⚡️ A fully-featured and blazing-fast Swift API client to interact with Algolia.

The perfect starting point to integrate Algolia within your Swift project Documentation • Community Forum • Stack Overflow • Report a bug • FAQ • Supp

Algolia 192 Dec 23, 2022
Simple proxy in Swift for converting between HTTP and API Gateway Lambda payloads

SwiftLambdaProxy A simple proxy that can convert HTTP requests to Lambda API Gat

Jānis Kiršteins 1 Jan 3, 2022
MpesaSDK - Swift SDK for the M-Pesa API (Mozambique)

M-Pesa SDK Swift package for M-Pesa API (Mozambique) Ready Methods/APIs C2B B2B

Algy Ali 16 Jul 29, 2022
Unofficial Notion API SDK for iOS & macOS

NotionSwift Unofficial Notion SDK for iOS & macOS. This is still work in progress version, the module interface might change. API Documentation This l

Wojciech Chojnacki 59 Jan 8, 2023
150,000+ stickers API & SDK for iOS Apps.

English | 한국어 Stipop UI SDK for iOS Stipop SDK provides over 150,000 .png and .gif stickers that can be easily integrated into mobile app chats, comme

Stipop, Inc. 19 Dec 20, 2022
iOS SDK for the Box Content API

Box iOS SDK Getting Started Docs: https://developer.box.com/guides/mobile/ios/quick-start/ NOTE: The Box iOS SDK in Objective-C (prior to v3.0.0) has

Box 112 Dec 19, 2022
Sample iOS AR app using AR Quick Look API

ARQLSanta This is a minimal AR iOS app that uses the AR Quick Look API, displayi

Yasuhito Nagatomo 9 Aug 23, 2022
iOS SDK for access the OpenCage Geocoding API

OpenCageSDK Requirements OpenCageSDK works on iOS 9+ and requires ARC to build. It depends on the following Apple frameworks, which should already be

OpenCage GmbH 1 Jun 30, 2020
A framework that enhances HealthKit and the Fitbit API for iOS

VitoKit ?? Welcome to VitoKit... A framework that enhances HealthKit and the Fitbit API for iOS ✅ Features Wonderfully crafted animations Speedy setup

Vito 6 Nov 26, 2022
This project explores the capabilities of the new iOS 16+ Passkeys API to support password-less authentications.

iOS 16+ Passkeys Swift Sample This project explores the capabilities of the new iOS 16+ Passkeys API to support password-less authentications. ⚠️ This

Hans Knöchel 9 Dec 21, 2022
Open-source API Client for iOS, iPadOS, macOS. Built with SwiftUI

Yogu Open-source API Client for iOS, iPadOS, macOS. Built with SwiftUI ?? Yogu is currently in development, and not actually usable yet. Please DO NOT

Beomjun Gil 5 Oct 29, 2022
This is swift project example to connect VNPTSmartCA SDK using Swift Language.

Example source code to integrate with VNPTSmartCA iOS SDK To run the example project, clone repository, and run pod install Requirements Installation

null 1 Feb 14, 2022
Home-assistant-swift-sdk - Used to integrate the Home Assistant APIs with your Swift-based apps.

home-assistant-swift-sdk This open-source library allows you to interact with a Home Assistant instance in your Swift-based (e.g., iOS, macOS, etc.) a

Alexander Golden 0 Dec 31, 2021
Azure Functions in Swift! Purely in Swift!

Azure Functions for Swift ⚡️ Write Azure Functions in Swift. This framework supports the new Azure Functions Custom Handlers (starting from 0.6.0) in

Saleh Albuga 87 Jan 3, 2023
Official Appwrite Swift SDK 🦅🍎

Appwrite Swift SDK This SDK is compatible with Appwrite server version 0.11.x. For older versions, please check previous releases. This is the Swift S

Appwrite 27 Dec 25, 2022