【问题标题】:Discord bot unable to play song using ytdl-coreDiscord bot 无法使用 ytdl-core 播放歌曲
【发布时间】:2023-04-05 02:20:01
【问题描述】:

我遇到了 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】:

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

    npm 卸载 ytdl-core npm 卸载 ytdl-core-discord npm install ytdl-core npm install ytdl-core-discord

    【讨论】:

      猜你喜欢
      • 2018-05-09
      • 2020-07-31
      • 2018-07-27
      • 1970-01-01
      • 2017-02-09
      • 2018-04-13
      • 2021-04-28
      • 2018-05-17
      • 2021-12-06
      相关资源
      最近更新 更多