DiscordKit feat: impl getGatewayURL

This commit is contained in:
2026-03-12 08:00:07 -04:00
parent cc489fccb6
commit d42227ba55
9 changed files with 135 additions and 27 deletions

View File

@@ -1,5 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import DiscordBM
struct MessageHandler {

View File

@@ -1,5 +1,7 @@
import Foundation
#if canImport(FoundationNetworking)
import FoundationNetworking
#endif
import XMLCoder
import DiscordBM

View File

@@ -1,5 +1,6 @@
import Foundation
import DiscordBM
import DiscordKit
import SwiftDotenv
@main
@@ -10,28 +11,33 @@ struct Zundamon {
let tmp = Result { try Dotenv.configure() }
switch (tmp) {
case .success:
print("Loaded .env file")
break
case .failure:
print("Failed to load .env file")
break
}
let token = ProcessInfo.processInfo.environment["DISCORD_TOKEN"]!
let bot = await BotGatewayManager(token: token, intents: [.guildMessages, .messageContent])
guard !token.isEmpty else { fatalError("Err: Empty DISCORD_TOKEN. Exiting...") }
await withTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
await bot.connect()
let tmp = try! await bot.client.getOwnUser()
ownID = try! tmp.decode().id
}
let bot = try await DiscordKit.Bot(token: token)
for await event in await bot.events {
taskGroup.addTask {
await EventHandler(event: event, client: bot.client).handleAsync()
}
}
}
// let bot = await BotGatewayManager(token: token, intents: [.guildMessages, .messageContent])
//await withTaskGroup(of: Void.self) { taskGroup in
// taskGroup.addTask {
// await bot.connect()
// let tmp = try! await bot.client.getOwnUser()
// ownID = try! tmp.decode().id
// }
// for await event in await bot.events {
// taskGroup.addTask {
// await EventHandler(event: event, client: bot.client).handleAsync()
// }
// }
//}
}
}