Swiftpack.co - Defxult/Discord.swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by Defxult.
Defxult/Discord.swift v0.0.2-alpha
A Discord API library written in Swift for creating your own bot.
⭐️ 33
🕓 28 weeks ago
.package(url: "https://github.com/Defxult/Discord.swift.git", from: "v0.0.2-alpha")


A Discord API library written in Swift.

🌍 Links

😎 Key Features

  • Asynchronous functionality using async and await
  • Full application command support
    • ☑ Slash commands
    • ☑ Message commands
    • ☑ User commands
  • Full message components support
    • ☑ Buttons
    • ☑ Select menus
    • ☑ Modals/text input

Application Commands Example

import Discord

let bot = Bot(token: "...", intents: Intents.default)

    name: "example",
    description: "Example command",
    guildId: nil,
    onInteraction: { interaction in
        try! await interaction.respondWithMessage("This is an example", ephemeral: true)

    name: "Who is",
    guildId: 1234567890123456789,
    onInteraction: { interaction in
        try! await interaction.respondWithMessage("...")

try! await bot.syncApplicationCommands() // Only needs to be done once

Event Listener Example

import Discord

let bot = Bot(token: "...", intents: Intents.default)

class MyListener : EventListener {
    override func onMessageCreate(message: Message) async {
        // Don't respond to our own message
        guard !message.author.isBot else {

        if message.content == "hi swifty" {
            try! await message.channel.send("Hello!")

try! bot.addListeners(MyListener(name: "example"))

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/Defxult/Discord.swift.git", .exact("<version here>"))
// ...
dependencies: [
    .product(name: "Discord", package: "Discord.swift")


Stars: 33
Last commit: 2 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

9 weeks ago

New Features

  • Added parameter platform to EventListener.onPresenceUpdate()
  • Implementation of premium app subscriptions
    • Added struct Application.Sku
    • Added enum Application.SkuType
    • Added enum Application.SkuFlag
    • Added struct Application.Entitlement
    • Added enum Application.EntitlementType
    • Added property Interaction.entitlements
    • Added method Interaction.respondWithPremiumRequired()
    • Added enum case InteractionCallbackType.premiumRequired
    • Added method Bot.createTestEntitlement()
    • Added method Bot.entitlements()
    • Added method Bot.skus()
    • Added method EventListener.onEntitlementCreate()
    • Added method EventListener.onEntitlementUpdate()
    • Added method EventListener.onEntitlementDelete()

Bug Fixes

  • Fixed an issue where the bot would disconnect randomly after an arbitrary amount of time. With this fix, an additional layer of gateway disconnect protection has been added. The bot is now aware of if it did/did not receive a heartbeat ACK in response to a sent heartbeat, and will reconnect if a heartbeat ACK was not sent by Discord.
  • Fixed an issue where if a Discord server outage occurred, upon the guild being available again, there was a possibility that its cached members in property Guild.members could be removed/replaced.
  • Fixed an issue where it was possible to have multiple heartbeats being sent simultaneously after a new gateway session was started due to an unlikely invalidated session.


  • (Breaking Change) Removed EventListener.onDisconnect()
  • (Breaking Change) Parameter activities in EventListener.onPresenceUpdate() is longer an optional type.

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