【发布时间】:2019-07-03 23:24:11
【问题描述】:
我快要把我的电脑扔出窗外了。我只是不明白为什么这不起作用:
async function play(message, msg) {
addytb(message, msg[3]).catch(err => {console.log('err');});
}
async function addytb(message, url) {
ytbapi.getVideo(url)
.then(video => {
message.channel.send(`J'ai ajouté ${video.title} à la queue !`);
queue.get(message.guild.id).push({"url": url, "type": 'youtube', "title": video.title});
})
.catch(() => {
message.channel.send(`J'ai pas réussi à ajouter ça à la queue !`);
throw 'error';
});
}
我已经在互联网上搜索了 2 个小时,但我找不到为什么我一直有未处理的承诺变暖。我认为这是因为 ytbapi.getVideo() 是异步的,但我不知道该怎么做。
谢谢。
【问题讨论】:
-
为什么在代码中使用
async关键字,然后使用.then和.catch? -
我尝试了几种解决方案,并没有在发布前删除异步。我知道他们在那里什么也没做。
标签: javascript node.js try-catch