Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/40.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js TypeError:无法读取属性';长度';未定义的特定bug的定义_Node.js_Discord.js_Ytdl - Fatal编程技术网

Node.js TypeError:无法读取属性';长度';未定义的特定bug的定义

Node.js TypeError:无法读取属性';长度';未定义的特定bug的定义,node.js,discord.js,ytdl,Node.js,Discord.js,Ytdl,我的机器人使用/play命令来选择歌曲,该命令以前提供了此列表 突然出现错误“无法读取未定义的属性‘length’”,我不明白为什么它以前工作正常 在这里,我留下了我认为发生错误的特定部分 const videos = await youtube.searchVideos(query, 5).catch(async function() { await message.say( '> There was a problem searching the vid

我的机器人使用/play命令来选择歌曲,该命令以前提供了此列表

突然出现错误“无法读取未定义的属性‘length’”,我不明白为什么它以前工作正常

在这里,我留下了我认为发生错误的特定部分

const videos = await youtube.searchVideos(query, 5).catch(async function() {
      await message.say(
        '> There was a problem searching the video you requested >.<'
      ).then(message.react('❌'));
      return;
    });
    if (videos.length < 5 || !videos) {
      message.say(
        `> I had some trouble finding what you were looking for, please try again or be more specific`
      ).then(message.react('❌'));
      return;
    }
    const videosNameArr = [];
    for (let i = 0; i < videos.length; i++) {
      videosNameArr.push(`${i + 1}: ${videos[i].title}`);
    }
    videosNameArr.push('cancel');
    const embed = new MessageEmbed()
      .setColor('#ffffff')
      .setTitle('Choose a song/video.')
      .addField('Song 1', videosNameArr[0])
      .addField('Song 2', videosNameArr[1])
      .addField('Song 3', videosNameArr[2])
      .addField('Song 4', videosNameArr[3])
      .addField('Song 5', videosNameArr[4])
      .addField('Exit', 'Cancel');
    var songEmbed = await message.channel.send({ embed });
    message.channel
      .awaitMessages(
        function(msg) {
          return (msg.content > 0 && msg.content < 6) || msg.content === 'cancel';
        },
        {
          max: 1,
          time: 60000,
          errors: ['time']
        }
      )
      .then(function(response) {
        const videoIndex = parseInt(response.first().content);
        if (response.first().content === 'cancel') {
          songEmbed.delete().then(message.channel.send("> Song canceled"));;
          return;
        }
const videos=wait youtube.searchVideos(查询,5.catch)(异步函数(){
等待消息(

“>搜索您请求的视频时出现问题>确定。因此,您不应该使用
const videos=await youtube.searchVideos(query,5).catch(async function(){
),而应该尝试
await youtube.searchVideos(query,5)。然后(videos=>{
),甚至将其分成两行


这里出现了一个错误,因为视频不是在函数中声明的,而是在函数外部声明的,因此它没有内容。要自己查找错误,可以使用
console.log()
检查变量及其内容,这对查找问题非常有帮助。
如果我上面的回答不能解决问题,请告诉我,我会更详细地检查这个问题。

嘿,它给了我一个非常简单的新错误。你的函数不是
async
。请确保将
async
关键字放在你的函数声明(
async function(){…}
async()=>{…})前面
)@Lioness100我不太懂,你能用我的代码来做吗?请。我尝试了
等待youtube。搜索视频(查询,5)。捕获(异步(视频)=>{
但给我
参考错误:视频未定义