fwcd / swift-discord

Discord client library for Swift

Home Page:https://fwcd.github.io/swift-discord/documentation/discord

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Discord Client for Swift

Build Docs

A client library for the Discord API written in Swift.

This project is a fork of nuclearace's SwiftDiscord, which is no longer actively maintained as of 2023. Among other changes, the codebase has been refactored to employ modern Swift patterns, such as value types and Codable, along with support for the v9 API.

Example

A simple Discord bot that responds to every "ping" message with "pong" could be implemented as follows:

import Discord
import Dispatch

class PingPongBot: DiscordClientDelegate {
    private var client: DiscordClient!

    init() {
        client = DiscordClient(token: "Bot <your token>", delegate: self)
        client.connect()
    }

    func client(_ client: DiscordClient, didCreateMessage message: DiscordMessage) {
        if message.content == "ping" {
            client.sendMessage("pong", to: message.channelId)
        }
    }
}

let bot = PingPongBot()
dispatchMain()

You can run this example (which is provided as a snippet) with

swift run PingPongBot <your token>

Check out the docs for more detailed information about the API.

Features

  • macOS and Linux support
  • v9 API (including threads, interactions, slash commands and message components)
  • Configurable sharding

Requirements

  • Swift 5.7+

Building

swift build

About

Discord client library for Swift

https://fwcd.github.io/swift-discord/documentation/discord

License:MIT License


Languages

Language:Swift 100.0%