Compare commits
2 Commits
58e4af94fd
...
7daab42d5f
Author | SHA1 | Date |
---|---|---|
Jill | 7daab42d5f | |
Jill | e4bdf94c5c |
53
src/index.js
53
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;
|
||||
}
|
||||
|
||||
|
@ -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];
|
||||
|
|
Reference in New Issue