-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPingBot.swift
More file actions
33 lines (29 loc) · 1.03 KB
/
PingBot.swift
File metadata and controls
33 lines (29 loc) · 1.03 KB
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
29
30
31
32
33
import SwiftDisc
import Foundation
@main
struct PingBotMain {
/// Starts a minimal ping/pong bot for quick connectivity testing.
static func main() async {
let token = ProcessInfo.processInfo.environment["DISCORD_BOT_TOKEN"] ?? "YOUR_BOT_TOKEN"
let client = DiscordClient(token: token)
await client.setOnReady { info in
print("✅ Connected as: \(info.user.username)")
}
await client.setOnMessage { msg in
if msg.content?.lowercased() == "ping" {
do {
try await client.sendMessage(channelId: msg.channel_id, content: "Pong!")
} catch {
print("Failed to send Pong: \(error)")
}
}
}
do {
try await client.loginAndConnect(intents: [.guilds, .guildMessages, .messageContent])
let events = await client.events
for await _ in events { /* keep alive */ }
} catch {
print("❌ Error: \(error)")
}
}
}