Discord bot无法使用ytdl-core播放歌曲

时间:2020-03-26 09:48:30

标签: javascript node.js discord discord.js

我的ytdl-core有问题。我的机器人无法播放任何内容。在我的控制台中,它显示Playing: (song),但根本不播放任何内容。一切正常,但不能播放任何歌曲。这是代码。

const config = require('../config/settings.json');
const queueFilename = './data/queue.txt';

const queue = fs.readFileSync(queueFilename).toString().split('\n');
const queueLength = queue.length;

async function playMusic(conn, entry = 0) {
  const song = queue[entry];

  try {
    const stream = ytdl(song, { 
      quality: 'highestaudio',
      highWaterMark: 1<<25
     });

    stream.on('info', info => {
      curSong = info.title;
      logger.info(`Playing: ${curSong}`);
      updatePresence(`► ${curSong}`);

      if (listeners <= 1) {
        dispatcher.pause();
        updatePresence(`❙ ❙ ${curSong}`);
        logger.info(`Nobody is listening in ${channel.name}, music has been paused.`);
      }
    });
  
    dispatcher = await conn.play(stream);
  
    dispatcher.on('end', () => {
      if (entry == queueLength - 1) playMusic(conn);
      else playMusic(conn, entry + 1);
    });
  
    dispatcher.on('error', err => {
      logger.error(err);
      if (entry == queueLength - 1) playMusic(conn);
      else playMusic(conn, entry + 1);
    });
  } catch (err) {
    logger.error(err);
    if (entry == queueLength - 1) playMusic(conn);
    else playMusic(conn, entry + 1);
  }
}

1 个答案:

答案 0 :(得分:1)

我遇到了同样的错误,我不知道是什么原因造成的,但我所做的是卸载它并重新安装它,现在它可以正常工作了。使用:

npm 卸载 ytdl-core npm 卸载 ytdl-core-discord npm 安装 ytdl 核心 npm 安装 ytdl-core-discord