-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPingBot.swift
More file actions
27 lines (23 loc) · 802 Bytes
/
PingBot.swift
File metadata and controls
27 lines (23 loc) · 802 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
import SwiftDisc
import Foundation
@main
struct PingBotMain {
static func main() async {
let token = ProcessInfo.processInfo.environment["DISCORD_TOKEN"] ?? "YOUR_BOT_TOKEN"
let client = DiscordClient(token: token)
client.onReady = { info in
print("✅ Connected as: \(info.user.username)")
}
client.onMessage = { msg in
if msg.content.lowercased() == "ping" {
_ = try? await client.sendMessage(channelId: msg.channel_id, content: "Pong!")
}
}
do {
try await client.loginAndConnect(intents: [.guilds, .guildMessages, .messageContent])
for await _ in client.events { /* keep alive */ }
} catch {
print("❌ Error: \(error)")
}
}
}