尝试获取视频作者姓名不和谐机器人时出错

时间:2020-08-05 13:56:43

标签: javascript node.js discord discord.js

我试图在我的不和谐播放命令中使用作者视频的名称,但出现此错误...

中止(TypeError:无法读取未定义的属性“作者”)。使用-s ASSERTIONS = 1进行构建以获取更多信息。 (使用node --trace-uncaught ...显示引发异常的位置)

const vidRequester = message.author;
        const name = message.author.tag
        const songData = ytdl.getInfo(queue[0].url);
            const videoEmbed = new MessageEmbed()
              .setThumbnail(queue[0].thumbnail)
              .setColor('#FA8072')
                .addField('| ▶️ | Melodia actuala:', queue[0].title)
                .setAuthor('Playing | 69% ? | soft ?', "https://cdn.discordapp.com/emojis/496793735946960916.gif")
              .addField('⏲️ Durata:', queue[0].duration, true)
                .addField('Video Author', songData.videoDetails.author.name, true)
                .setFooter('Facut cu ? de @Petre Ispirescu#0060')
                .setTimestamp()

1 个答案:

答案 0 :(得分:0)

static playSong(queue, message) {
    const classThis = this; // use classThis instead of 'this' because of lexical scope below
    queue[0].voiceChannel
      .join()
      .then(function(connection) {
        const dispatcher = connection
          .play(
            ytdl(queue[0].url, {
              quality: 'highestaudio',
              highWaterMark: 1024 * 1024 * 10
            })
          )
          .on('start', function() {
            message.guild.musicData.songDispatcher = dispatcher;
            dispatcher.setVolume(message.guild.musicData.volume);
        const vidRequester = message.author;
        const name = message.author.tag
        const songData = ytdl.getInfo(queue[0].url);
            const videoEmbed = new MessageEmbed()
              .setThumbnail(queue[0].thumbnail)
              .setColor('#FA8072')
          .addField('| ▶️ | Melodia actuala:', queue[0].title)
          .setAuthor('Playing | 69% ? | soft ?', "https://cdn.discordapp.com/emojis/496793735946960916.gif")
              .addField('⏲️ Durata:', queue[0].duration, true)
          .addField('Video Author', songData.videoDetails.author.name, true)
          .setFooter('Facut cu ? de @Petre Ispirescu#0060')
          .setTimestamp()