DiscordKit: can now get to ready event

This commit is contained in:
2026-03-17 16:37:31 -04:00
parent 29a2b0370b
commit 7506a06d7f
6 changed files with 139 additions and 39 deletions

View File

@@ -7,36 +7,32 @@ struct Zundamon {
//nonisolated(unsafe) static private(set) var ownID: UserSnowflake? = nil
static func main() async throws {
let tmp = Result { try Dotenv.configure() }
switch (tmp) {
case .success:
break
case .failure:
print("Failed to load .env file")
break
if case .failure = Result(catching: { try Dotenv.configure() }) {
print("Failed to load .env file")
}
let token = ProcessInfo.processInfo.environment["DISCORD_TOKEN"]!
guard !token.isEmpty else { fatalError("Err: Empty DISCORD_TOKEN. Exiting...") }
let bot = try await DiscordKit.Bot(token: token)
let intents: Intents = [.guilds, .guildMessages, .messageContent, .guildMembers, .directMessages]
print(intents)
let bot = try await DiscordKit.Bot(token: token, intents: intents)
// 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
// }
await withThrowingTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
try await bot.connect()
}
// for await event in await bot.events {
// taskGroup.addTask {
// await EventHandler(event: event, client: bot.client).handleAsync()
// }
// }
//}
taskGroup.addTask {
for await event in await bot.events {
dump(event)
}
}
}
}
}