Discord 机器人无法使用 ytdl-core 播放歌曲

问题描述 投票:0回答:1

我的 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);
  }
}
javascript node.js discord discord.js
1个回答
1
投票

我有同样的错误,我不知道是什么原因造成的,但我所做的就是卸载它并重新安装它,现在它工作正常。
使用这些命令:

npm uninstall ytdl-core
npm uninstall ytdl-core-discord

npm install ytdl-core
npm install ytdl-core-discord
© www.soinside.com 2019 - 2024. All rights reserved.