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 };