Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fwcd/swift-discord
Discord client library for Swift
https://github.com/fwcd/swift-discord
discord discord-api swift
Last synced: 28 days ago
JSON representation
Discord client library for Swift
- Host: GitHub
- URL: https://github.com/fwcd/swift-discord
- Owner: fwcd
- License: mit
- Created: 2019-08-27T17:48:47.000Z (over 5 years ago)
- Default Branch: main
- Last Pushed: 2024-10-02T00:11:17.000Z (3 months ago)
- Last Synced: 2024-11-30T04:44:25.248Z (about 1 month ago)
- Topics: discord, discord-api, swift
- Language: Swift
- Homepage: https://fwcd.github.io/swift-discord/documentation/discord
- Size: 87.4 MB
- Stars: 8
- Watchers: 2
- Forks: 0
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Discord Client for Swift
[![Build](https://github.com/fwcd/swift-discord/actions/workflows/build.yml/badge.svg)](https://github.com/fwcd/swift-discord/actions/workflows/build.yml)
[![Docs](https://github.com/fwcd/swift-discord/actions/workflows/docs.yml/badge.svg)](https://fwcd.github.io/swift-discord/documentation/discord)A client library for the [Discord API](https://discord.com/developers/docs) written in Swift.
This project is a fork of [nuclearace's](https://github.com/nuclearace) [`SwiftDiscord`](https://github.com/nuclearace/SwiftDiscord), which is no longer actively maintained as of 2023. Among other changes, the codebase has been [refactored](https://github.com/fwcd/swift-discord/pull/4) 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:
```swift
import Discord
import Dispatchclass PingPongBot: DiscordClientDelegate {
private var client: DiscordClient!init() {
client = DiscordClient(
token: "Bot ",
delegate: self,
configuration: [.intents([.guildMessages, .messageContent])]
)
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](Snippets/PingPongBot.swift)) with
```sh
swift run PingPongBot
```Check out the [docs](https://fwcd.github.io/swift-discord/documentation/discord) for more detailed information about the API.
## Features
- macOS and Linux support
- v10 API (including threads, interactions, slash commands and message components)
- Configurable sharding## Requirements
- Swift 5.7+
## Building
`swift build`