const videoPlayer = async (guild) => { const songQueue = queue.get(guild.id); if (songQueue.audioPlayer.state.status !== AudioPlayerStatus.Idle || songQueue.songs.length === 0) { return; } const nextTrack = songQueue.songs.shift(); try { const process = raw( nextTrack.url, { o: '-', q: '', f: 'bestaudio[ext=webm+acodec=opus+asr=48000]/bestaudio', r: '100K', }, { stdio: ['ignore', 'pipe', 'ignore'] }, ); if (!process.stdout) { Promise.reject(new Error('No stdout')); return; } const stream = process.stdout; const onError = (error) => { if (!process.killed) process.kill(); stream.resume(); Promise.reject(error); }; process .once('spawn', () => { demuxProbe(stream) .then((probe) => Promise.resolve(createAudioResource(probe.stream, { inputType: probe.type }))) .catch(onError); }) .catch(onError); songQueue.audioPlayer.play(process); } catch (error) { // If an error occurred, try the next item of the queue instead return videoPlayer(guild); } };