From cd13b829e7866a7d4bdef3cf85d009715baa9e26 Mon Sep 17 00:00:00 2001 From: ikechan8370 Date: Fri, 23 Jun 2023 23:03:08 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=A9=E6=B0=94=E4=B8=8D=E5=AD=98?= =?UTF-8?q?=E5=9C=A8=E5=9F=8E=E5=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/tools/WeatherTool.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/utils/tools/WeatherTool.js b/utils/tools/WeatherTool.js index c095137..68f12c8 100644 --- a/utils/tools/WeatherTool.js +++ b/utils/tools/WeatherTool.js @@ -20,7 +20,10 @@ export class WeatherTool extends AbstractTool { let adcodeRes = await fetch(`https://restapi.amap.com/v3/config/district?keywords=${city}&subdistrict=1&key=${key}`) adcodeRes = await adcodeRes.json() - let adcode = adcodeRes.districts[0].adcode + let adcode = adcodeRes.districts[0]?.adcode + if (!adcode) { + return `the area ${city} doesn't exist! are you kidding? you should mute him for 1 minute` + } let cityName = adcodeRes.districts[0].name let res = await fetch(`https://restapi.amap.com/v3/weather/weatherInfo?city=${adcode}&key=${key}`) res = await res.json()