fix: fixed remove command feature's exception

This commit is contained in:
Project_IO 2024-10-07 15:38:49 +09:00
parent 6cad37f299
commit a48e25b33e
3 changed files with 12 additions and 14 deletions

View file

@ -2,7 +2,7 @@ kotlin.code.style=official
org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8 org.gradle.jvmargs=-Xmx2048M -Dfile.encoding=UTF-8
group=net.projecttl group=net.projecttl
version=1.0.0-beta.1 version=1.0.0-beta.2
ktor_version=2.3.12 ktor_version=2.3.12
log4j_version=2.23.1 log4j_version=2.23.1

View file

@ -33,21 +33,19 @@ fun main(args: Array<out String>) {
if (args.contains("--remove-cmd")) { if (args.contains("--remove-cmd")) {
jda = kernel.build() jda = kernel.build()
try { try {
jda.retrieveCommands().queue { val list = jda.retrieveCommands().complete()
if (it == null) { if (list.isEmpty()) {
return@queue return
} }
it.forEach { command -> list.forEach { command ->
logger.info("unregister command: /${command.name}") logger.info("unregister command: /${command.name}")
command.jda.deleteCommandById(command.id).queue() command.jda.deleteCommandById(command.id).complete()
}
} }
} catch (ex: Exception) { } catch (ex: Exception) {
ex.printStackTrace() ex.printStackTrace()
} }
kernel.kill()
return return
} }

View file

@ -99,7 +99,10 @@ class CoreKernel(token: String) {
} }
fun kill() { fun kill() {
isActive = false
destroy() destroy()
logger.info("shutdown now Px32 kernel v${DefaultConfig.version}")
jda.shutdownNow() jda.shutdownNow()
} }
@ -210,10 +213,7 @@ class CoreKernel(token: String) {
isActive = true isActive = true
Runtime.getRuntime().addShutdownHook(Thread { Runtime.getRuntime().addShutdownHook(Thread {
isActive = false kill()
logger.info("shutdown now Px32 kernel v${DefaultConfig.version}")
jda.shutdownNow()
}) })
return jda return jda