Files
zunda-bot/Sources/zundamon/Zundamon.swift

48 lines
1.4 KiB
Swift

import Foundation
import DiscordKit
import SwiftDotenv
@main
struct Zundamon {
//nonisolated(unsafe) static private(set) var ownID: UserSnowflake? = nil
static func main() async throws {
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 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 withThrowingTaskGroup(of: Void.self) { taskGroup in
taskGroup.addTask {
try await bot.connect()
}
taskGroup.addTask {
for await event in await bot.events {
dump(event)
}
}
}
}
}
//struct EventHandler: GatewayEventHandler {
// let event: Gateway.Event
// let client: any DiscordClient
//
// func onMessageCreate(_ payload: Gateway.MessageCreate) async throws {
// try await MessageHandler(ctx: payload, client: client).handle()
// }
//
//}