-
Notifications
You must be signed in to change notification settings - Fork 1
Home
A modern, Swift-native Discord API library for building powerful bots with async/await, type-safe models, and production-ready features.
- Repository: https://github.com/M1tsumi/SwiftDisc
- Examples: https://github.com/M1tsumi/SwiftDisc/tree/main/Examples
- Issues: https://github.com/M1tsumi/SwiftDisc/issues
- Discussions: https://github.com/M1tsumi/SwiftDisc/discussions
- Join Discord: https://discord.gg/6nS2KqxQtj
Add to your Package.swift:
dependencies: [
.package(url: "https://github.com/M1tsumi/SwiftDisc.git", from: "0.10.0")
]
targets: [
.target(name: "YourBot", dependencies: ["SwiftDisc"])
]Minimums: iOS 14, macOS 11, tvOS 14, watchOS 7, Windows (Swift 5.9+).
import SwiftDisc
@main
struct MyFirstBot {
static func main() async {
let token = ProcessInfo.processInfo.environment["DISCORD_BOT_TOKEN"] ?? ""
let client = DiscordClient(token: token)
do {
try await client.loginAndConnect(intents: [.guilds, .guildMessages, .messageContent])
for await event in client.events {
switch event {
case .ready(let info):
print("✅ Bot is online as \(info.user.username)!")
case .messageCreate(let msg) where msg.content == "!hello":
try await client.sendMessage(channelId: msg.channel_id, content: "Hello!")
default:
break
}
}
} catch {
print("SwiftDisc error: \(error)")
}
}
}Tips:
- Enable necessary gateway intents in the Discord Developer Portal (e.g.
MESSAGE_CONTENT). - Never hardcode tokens; prefer environment variables.
- Gateway: Async event stream, heartbeats, resume, sharding.
- REST: Channels, messages, guilds, roles, webhooks, slash commands.
- DX: Type-safe APIs, clear errors, helpful utilities (embeds, components).
- Extras: Autocomplete, file uploads, caching, permissions utilities.
- Ping Bot: Basic message handling
- Commands Bot: Prefix routing and help
- Slash Bot: Modern interactions
- File Upload Bot: Multipart uploads with embeds
Browse: https://github.com/M1tsumi/SwiftDisc/tree/main/Examples
- Join Discord: https://discord.gg/6nS2KqxQtj
- Documentation: This wiki + README in the repo
- Report Issues: https://github.com/M1tsumi/SwiftDisc/issues
- Propose Ideas: https://github.com/M1tsumi/SwiftDisc/discussions
- Open an issue for major changes before a PR.
- Follow Swift API Design Guidelines.
- Include tests when possible.
License: MIT
- Custom WebSocket adapter path for Windows compatibility (URLSession-based adapter used across platforms)
- Continuous integration for macOS and Windows
- Platform-specific optimizations
- Embeds support in message sending and interaction responses
- Minimal slash commands: create global/guild commands and reply to interactions
-
Server/CLI: Build with SwiftPM; run with environment variable
DISCORD_TOKEN - Use a process supervisor (systemd, launchd, PM2, or Docker) to keep the bot running
- Set required intents in the Discord Developer Portal
- Configure shard count if you operate at scale; use
ShardManager
- Enable logging (stdout/stderr) and retain logs
- Ensure outbound network access to Discord domains; time sync is recommended
- Horizontal: Multiple processes with shard ranges
- Respect REST and gateway limits; avoid per-second spikes
- Never commit tokens. Use environment variables or secret stores (Keychain/KeyVault/Parameter Store)
- Use GitHub Actions CI provided (build/test/coverage)
- Add a deploy job to your infrastructure
- Use environment variables for bot tokens
- Leverage secure storage on device platforms (Keychain, credential managers)
- Follow Discord's developer policies
- Be mindful when requesting privileged intents
- Discord Server: Join the community for support, announcements, and discussions
- GitHub Issues: Report bugs and request features
- GitHub Discussions: Ask questions and share your projects
Contributions are welcome! Please read the contributing guidelines before submitting pull requests.
SwiftDisc adapts proven patterns from discord.py (BSD-licensed), implementing them idiomatically for Swift. Key adaptations include intents, event dispatch, and rate limiting strategies.
This project follows Semantic Versioning. See CHANGELOG.md for detailed release notes.
SwiftDisc is released under the MIT License. See the LICENSE file for details.
Built with ❤️ for the Swift and Discord communities
Repository: https://github.com/M1tsumi/SwiftDisc