-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandFrameworkBot.swift
More file actions
28 lines (23 loc) · 763 Bytes
/
CommandFrameworkBot.swift
File metadata and controls
28 lines (23 loc) · 763 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import Foundation
import SwiftDisc
// Example: a minimal bot showing the CommandRouter usage.
@main
struct CommandFrameworkBot {
static func main() async {
let token = ProcessInfo.processInfo.environment["DISCORD_TOKEN"] ?? "YOUR_TOKEN_HERE"
let client = DiscordClient(token: token)
let router = CommandRouter(prefix: "!")
router.register("ping") { ctx in
try? await ctx.reply("Pong!")
}
// Attach simple message handler to the client's event system.
client.onMessageCreate { message in
await router.processMessage(message)
}
do {
try await client.start()
} catch {
print("Client failed to start: \(error)")
}
}
}