如果此命令不是有效的 api url,如何使此命令不会破坏整个机器人



如果我输入一个有效的API密钥,它就会工作,如果我不这样做,它不仅不工作,还会破坏整个bot。

const text = options.getString('url')
axios.get(text).then(resp => { //TODO: make it so the bot doesn't have to be rehosted if the API isn't valid
const contenttotext = JSON.stringify(resp.data)
interaction.reply({
content: contenttotext
})
});
axios.get(text)
.then((res) => {
/*handle response*/
})
.catch((err) => {
/* handle error */
})

你应该好好看看Promises,以及Axios的示例部分,它展示了这一点。

最新更新