more error handling
This commit is contained in:
parent
e4bdf94c5c
commit
7daab42d5f
51
src/index.js
51
src/index.js
|
@ -113,35 +113,42 @@ async function play(song, id, connection, channel) {
|
||||||
url = out.stdout;
|
url = out.stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
const stream = got(url, {isStream: true});
|
try {
|
||||||
const resource = Voice.createAudioResource(stream, { inputType: Voice.StreamType.Arbitrary });
|
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);
|
console.log(err);
|
||||||
channel.send(`failed to play track: \`\`\`${err}\`\`\``);
|
channel.send(`failed to play track: \`\`\`${err}\`\`\``);
|
||||||
advanceQueue(id, channel, subscription, connection);
|
advanceQueue(id, channel, subscription, connection);
|
||||||
return;
|
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;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Reference in New Issue