diff --git a/src/index.js b/src/index.js index f0275ea..2434c86 100644 --- a/src/index.js +++ b/src/index.js @@ -113,35 +113,42 @@ async function play(song, id, connection, channel) { url = out.stdout; } - const stream = got(url, {isStream: true}); - const resource = Voice.createAudioResource(stream, { inputType: Voice.StreamType.Arbitrary }); + try { + const stream = got(url, {isStream: true}); + const resource = Voice.createAudioResource(stream, { inputType: Voice.StreamType.Arbitrary }); - stream.on('error', err => { + stream.on('error', err => { + console.log(err); + channel.send(`failed to play track: \`\`\`${err}\`\`\``); + advanceQueue(id, channel, subscription, connection); + return; + }); + + if (players[id]) { + console.log('reusing player'); + player = players[id]; + } else { + console.log('creating new player'); + player = Voice.createAudioPlayer(); + players[id] = player; + subscription = connection.subscribe(player); + + player.on(Voice.AudioPlayerStatus.Idle, () => { + advanceQueue(id, channel, subscription, connection); + }); + player.on(Voice.AudioPlayerStatus.Playing, () => { + playerStartTime[id] = Date.now(); + }) + } + + player.play(resource); + } catch(err) { console.log(err); channel.send(`failed to play track: \`\`\`${err}\`\`\``); advanceQueue(id, channel, subscription, connection); return; - }); - - if (players[id]) { - console.log('reusing player'); - player = players[id]; - } else { - console.log('creating new player'); - player = Voice.createAudioPlayer(); - players[id] = player; - subscription = connection.subscribe(player); - - player.on(Voice.AudioPlayerStatus.Idle, () => { - advanceQueue(id, channel, subscription, connection); - }); - player.on(Voice.AudioPlayerStatus.Playing, () => { - playerStartTime[id] = Date.now(); - }) } - player.play(resource); - return player; }