我试图得到一个结果,但我找不到如何解决SyntaxError: await is only valid in async function
static async searchYoutube(query, message, voiceChannel) {
await youtube.searchVideos(query, 5).catch(videos => {
await message.say(
':x: There was a problem searching the video you requested!'
);
return;
});
if (videos.length < 5 || !videos) {
message.say(
`:x: I had some trouble finding what you were looking for, please try again or be more specific.`
);
return;
}
现在,他们还推荐了前面的颜色异步,我做到了,但这标志着另一个错误
TypeError: Cannot read property 'length' of undefined
static async searchYoutube(query, message, voiceChannel) {
await youtube.searchVideos(query, 5).catch(async (videos) => {
await message.say(
':x: There was a problem searching the video you requested!'
);
return;
});
if (videos.length < 5 || !videos) {
message.say(
`:x: I had some trouble finding what you were looking for, please try again or be more specific.`
);
return;
}