Discord bot fails to stream music using ytdl-core

I’m encountering issues where my Discord bot, which employs a YouTube downloader, logs ‘Now Streaming’ but no sound is produced. See the updated code sample:

const settings = require('./config.json');
const songList = require('fs').readFileSync('./songs.txt', 'utf8').split('\n');

async function streamTrack(connection, idx = 0) {
  const trackUrl = songList[idx];
  try {
    const audioSource = ytdl(trackUrl, { filter: 'audioonly', highWaterMark: 1 << 20 });
    const player = await connection.play(audioSource);
    console.log(`Now Streaming: ${trackUrl}`);
    player.on('finish', () => {
      if (idx + 1 < songList.length) streamTrack(connection, idx + 1);
    });
    player.on('error', error => {
      console.error(error);
      streamTrack(connection, (idx + 1) % songList.length);
    });
  } catch (error) {
    console.error(error);
    streamTrack(connection, (idx + 1) % songList.length);
  }
}

module.exports = { streamTrack };

I had a similar problem where the bot showed that it was playing the song, but no audio came through. After some investigation, I found that it was partly due to a conflict between the versions of discord.js and ytdl-core I was using. I resolved it by downgrading ytdl-core to a version that better supported my current setup. Also, verifying that the streaming options passed to ytdl-core, such as highWaterMark, were properly configured helped a lot. Checking your dependencies might be a good starting point, as subtle updates can sometimes break streaming functionality.