-2

我的代码如下为什么会出现这样的错误;

“ ReferenceError:未定义错误”

else if (processMethod.toUpperCase() === "COVID") {
    console.log("white", "get covid statics...");
    targetCountry = (await covid.parseCountry(UK)).countryid;
    if (err.message === "Failed to get country." || err.message === "Invalid Country Code") {

        const ErrMsg2 = new Discord.RichEmbed()
            ErrMsg2.setColor(0x00AE86)
            ErrMsg2.setTimestamp()
            ErrMsg2.setAuthor(message.author.username, message.author.avatarURL)
            ErrMsg2.setThumbnail(message.guild.iconURL)
            ErrMsg2.setDescription(`Failed Try Again`)
            ErrMsg2.setFooter("COVID SERVICES")
            message.channel.sendEmbed(ErrMsg2);
    }

}

4

1 回答 1

0

如果您正在进行错误处理,您需要先检测错误,请尝试使用try{}catch(){}

为您的代码

try {
   targetCountry = (await covid.parseCountry(UK)).countryid;
}
catch (err) {
    if (err.message === "Failed to get country." || err.message === "Invalid Country Code") { 
        // ...
    }
}
于 2020-05-23T01:13:37.517 回答