Compare commits

...

2 Commits

Author SHA1 Message Date
Jill 7daab42d5f more error handling 2021-11-07 15:30:06 +03:00
Jill e4bdf94c5c queue fix 2021-11-07 15:28:20 +03:00
1 changed files with 30 additions and 23 deletions

View File

@ -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;
}
@ -266,7 +273,7 @@ bot.on('messageCreate', async (msg) => {
if (q.length === 0) {
msg.channel.send('no songs queued!');
} else {
msg.channel.send(`${q.length} tracks\ntotal queue length: ${formatTime(q.reduce((p, c) => (p || {duration: 0}).duration || 0 + c.duration || 0))}\n` + '```' + q.slice(0, 10).map((m, i) => `${i === 0 ? 'now playing:' : i + '.'} ${m.title} ${(m.duration !== 0) ? formatTime(m.duration) : ''}`).join('\n') + '```');
msg.channel.send(`${q.length} tracks\ntotal queue length: ${formatTime(q.reduce((p, c) => p || 0 + c.duration || 0))}\n` + '```' + q.slice(0, 10).map((m, i) => `${i === 0 ? 'now playing:' : i + '.'} ${m.title} ${(m.duration !== 0) ? formatTime(m.duration) : ''}`).join('\n') + '```');
}
} else if (cmd === 'np' || cmd === 'nowplaying') {
const song = (queue[msg.guild.id] || [])[0];