Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/Defxult/Discord.swift
A Discord API library written in Swift for creating your own bot.
https://github.com/Defxult/Discord.swift
bot discord discord-api discord-api-wrapper discord-bot discord-buttons discord-components discord-library discord-slash-command discord-swift discord-swift-library discordkit framework library linux mac macos swift swift-discord-bot vapor
Last synced: 8 days ago
JSON representation
A Discord API library written in Swift for creating your own bot.
- Host: GitHub
- URL: https://github.com/Defxult/Discord.swift
- Owner: Defxult
- License: mit
- Archived: true
- Created: 2023-05-10T23:21:52.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-01-03T14:48:15.000Z (10 months ago)
- Last Synced: 2024-10-02T03:02:12.460Z (about 1 month ago)
- Topics: bot, discord, discord-api, discord-api-wrapper, discord-bot, discord-buttons, discord-components, discord-library, discord-slash-command, discord-swift, discord-swift-library, discordkit, framework, library, linux, mac, macos, swift, swift-discord-bot, vapor
- Language: Swift
- Homepage:
- Size: 10.4 MB
- Stars: 36
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
A Discord API library written in Swift.
## Links
- [Setup guide](https://discord-swift.gitbook.io/discord.swift/overview/getting-started)
- [Changelog](https://discord-swift.gitbook.io/discord.swift/resources/changelog)## Key Features
- Asynchronous functionality using `async` and `await`
- Full application command support
- [x] Slash commands
- [x] Message commands
- [x] User commands
- Full message components support
- [x] Buttons
- [x] Select menus
- [x] Modals/text input## Application Commands Example
```swift
import Discordlet bot = Bot(token: "...", intents: Intents.default)
bot.addSlashCommand(
name: "example",
description: "Example command",
guildId: nil,
onInteraction: { interaction in
try! await interaction.respondWithMessage("This is an example", ephemeral: true)
}
)bot.addUserCommand(
name: "Who is",
guildId: 1234567890123456789,
onInteraction: { interaction in
try! await interaction.respondWithMessage("...")
}
)try! await bot.syncApplicationCommands() // Only needs to be done once
bot.run()
```## Event Listener Example
```swift
import Discordlet 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 {
return
}if message.content == "hi swifty" {
try! await message.channel.send("Hello!")
}
}
}try! bot.addListeners(MyListener(name: "example"))
bot.run()
```
## Swift Package Manager
```swift
dependencies: [
.package(url: "https://github.com/Defxult/Discord.swift.git", .exact(""))
]
// ...
dependencies: [
.product(name: "Discord", package: "Discord.swift")
]
```