Swiftpack.co - SwiftcordApp/DiscordKit as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by SwiftcordApp.
SwiftcordApp/DiscordKit 1.0.0
The Discord API implementation behind Swiftcord, implemented completely from scratch in Swift
⭐️ 294
🕓 50 weeks ago
iOS macOS linux
.package(url: "https://github.com/SwiftcordApp/DiscordKit.git", from: "1.0.0")

DiscordKit

Package for interacting with Discord's API to build Swift bots

DiscordKit for Bots is now released! Use DiscordKit to create that bot you've been looking to make, in the Swift that you know and love!

About

DiscordKit is a Swift package for creating Discord bots in Swift.

If DiscordKit has helped you, please give it a ⭐ star and consider sponsoring! It keeps me motivated to continue developing this and other projects.

Installation

Swift Package Manager (SPM):

Package.swift

Add the following to your Package.swift:

.package(url: "https://github.com/SwiftcordApp/DiscordKit", branch: "main")
Xcode Project

Add a package dependancy in your Xcode project with the following parameters:

Package URL:

https://github.com/SwiftcordApp/DiscordKit

Branch:

main

Product:

  • ☑ DiscordKitBot

For more detailed instructions, refer to this page in the DiscordKit guide.

Example Usage

Create a simple bot with a /ping command:

import DiscordKitBot

let bot = Client(intents: .unprivileged)

// Guild to register commands in. If the COMMAND_GUILD_ID environment variable is set, commands are scoped
// to that server and update instantly, useful for debugging. Otherwise, they are registered globally.
let commandGuildID = ProcessInfo.processInfo.environment["COMMAND_GUILD_ID"]

bot.ready.listen {
    print("Logged in as \(bot.user!.username)#\(bot.user!.discriminator)!")

    try? await bot.registerApplicationCommands(guild: commandGuildID) {
        NewAppCommand("ping", description: "Ping me!") { interaction in
            try? await interaction.reply("Pong!")
        }
    }
}

bot.login() // Reads the bot token from the DISCORD_TOKEN environment variable and logs in with the token

// Run the main RunLoop to prevent the program from exiting
RunLoop.main.run()

(Yes, that's really the whole code, no messing with registering commands with the REST API or anything!)

Not sure what to do next? Check out the guide below, which walks you through all the steps to create your own Discord bot!

Resources

Here are some (WIP) resources that might be useful while developing with DiscordKit.

Platform Support

Currently, DiscordKit only offically supports macOS versions 11 and up. Theoretically, you should be able to compile and use DiscordKit on any Apple platform with equivalent APIs, however this has not been tested and is considered an unsupported setup.

DiscordKitBot and DiscordKitCore is supported on Linux, but not DiscordKit itself. However, you are able to develop and host bots made with DiscordKit on Linux.

Windows is not supported natively at the moment. The recommended method is to use Windows Subsystem for Linux to do any development/hosting of DiscordKit bots on Windows. Native support may come in the future.

GitHub

link
Stars: 294
Last commit: 5 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Finally, bot support!
50 weeks ago

DiscordKit for Bots: The missing Discord framework for bots you've been waiting for!

Now, you can build Discord bots in Swift with elegance, with beautiful and clean slash command builders and a well thought out API! Built on a solid battle-tested core also used in Swiftcord, DiscordKit's bot support has robust rock-solid performance even in the face of network instabilities and other unexpected conditions.

Although I've tried to consider as many common use cases, DiscordKit for Bots is still in early phases of support and might not have good support for more advanced uses. Contributions are welcome! <3

This is DiscordKit's first stable release, and as such there isn't a previous release to compare against. Here are some features of note:

  • Beautiful SwiftUI-like slash command builders, including modifiers and execution callbacks:

    NewAppCommand("hello", description: "Get a nice hello message") { interaction in
        print("Received hello interaction!")
        try? await interaction.reply("Hello there!")
    }
    

    produces the following (operational) command:

    image

    Register and respond to commands in one place!

  • Battle-tested WebSocket gateway reconnection logic, with zlib-stream compression support

  • Well-documented and well-though-out (bot) API

Get up to speed quick with the guide

Coming Soon:

  • Button component support
  • Image/attachment up/downloading

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