feat: add exception catch
This commit is contained in:
1 file changed
+34
-27
@@ -34,6 +34,7 @@ class WikipediaCommand : BaseCommand() {
|
|||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
}
|
}
|
||||||
val title = args.first()
|
val title = args.first()
|
||||||
|
try {
|
||||||
val response = Http.get<WikipediaResponse>(
|
val response = Http.get<WikipediaResponse>(
|
||||||
wikipediaAPI,
|
wikipediaAPI,
|
||||||
mapOf(
|
mapOf(
|
||||||
@@ -61,5 +62,11 @@ class WikipediaCommand : BaseCommand() {
|
|||||||
.addText(fullUrl)
|
.addText(fullUrl)
|
||||||
.build()
|
.build()
|
||||||
message.reply(msg)
|
message.reply(msg)
|
||||||
|
} catch (_: NoSuchElementException) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addText("没有查询到指定的wiki页面呢 >>> $title")
|
||||||
|
.build()
|
||||||
|
message.reply(msg)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user