【问题标题】:Error trying to get video author name discord bot尝试获取视频作者姓名不和谐机器人时出错
【发布时间】:2020-11-25 17:22:35
【问题描述】:

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

中止(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()

【问题讨论】:

  • TypeError: Cannot read property 'author' of undefined 这意味着当你这样做时message.author messageundefined。提供生成message 的代码。
  • 是的,我的错,我会做一个新的评论来放代码,但我不认为它来自消息
  • 您的 message 对象超出范围。您需要将其传递给方法。

标签: javascript node.js discord discord.js


【解决方案1】:

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-09-20
    • 2021-07-09
    • 2021-09-04
    • 2021-06-24
    • 2021-06-27
    • 2020-12-18
    • 2021-10-02
    相关资源
    最近更新 更多