play many songs at once
This commit is contained in:
parent
256bcba807
commit
58e4af94fd
74
src/index.js
74
src/index.js
|
@ -201,6 +201,42 @@ async function queueUp(url, id) {
|
|||
return [1, null];
|
||||
}
|
||||
|
||||
async function playOrQueue(qsong, channel, msg) {
|
||||
const connection = await checkVoiceChannel(msg);
|
||||
if (!connection) return;
|
||||
|
||||
console.log(`queueing ${qsong}`);
|
||||
channel.send(`queueing ${qsong}...`);
|
||||
|
||||
let [q, e] = await queueUp(qsong, msg.guild.id);
|
||||
if (!q && e) return msg.channel.send(e);
|
||||
const song = queue[msg.guild.id][queue[msg.guild.id].length - 1];
|
||||
|
||||
if (queue[msg.guild.id].length === 1) {
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setDescription(`now playing: **${song.titleFormat}**`)
|
||||
.setThumbnail(song.thumbnail)
|
||||
.setColor(embedColor)
|
||||
.setAuthor('foggy ♫', foggyImg);
|
||||
|
||||
msg.channel.send({embeds: [embed]});
|
||||
await play(queue[msg.guild.id][0], msg.guild.id, connection, msg.channel);
|
||||
} else {
|
||||
let queueString = `queued: **${song.titleFormat}** _at position ${queue[msg.guild.id].length - 1}_`;
|
||||
if (q > 1) queueString = `queued **${q} songs** _at positions ${queue[msg.guild.id].length - q} - ${queue[msg.guild.id].length - 1}_`;
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setDescription(queueString)
|
||||
.setColor(embedColor)
|
||||
.setAuthor('foggy ♫', foggyImg);
|
||||
msg.channel.send({embeds: [embed]});
|
||||
|
||||
if (!players[msg.guild.id] || players[msg.guild.id].state === Voice.AudioPlayerStatus.Idle || players[msg.guild.id].state === Voice.AudioPlayerStatus.Paused) {
|
||||
await play(queue[msg.guild.id][0], msg.guild.id, connection, msg.channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bot.on('messageCreate', async (msg) => {
|
||||
const content = msg.content;
|
||||
const params = content.replace(prefix, '').split(' ');
|
||||
|
@ -209,41 +245,11 @@ bot.on('messageCreate', async (msg) => {
|
|||
if (!msg.guild || !content.startsWith(prefix) || !msg.channel) return;
|
||||
|
||||
if ((cmd === 'play' || cmd === 'p') && params[1]) {
|
||||
const connection = await checkVoiceChannel(msg);
|
||||
if (!connection) return;
|
||||
const url = params.slice(1).join(" ");
|
||||
|
||||
console.log('queueing');
|
||||
msg.channel.send('queueing...');
|
||||
|
||||
let [q, e] = await queueUp(url, msg.guild.id);
|
||||
if (!q && e) [q, e] = await queueUp('ytsearch:' + url, msg.guild.id);
|
||||
if (!q && e) return msg.channel.send(e);
|
||||
const song = queue[msg.guild.id][queue[msg.guild.id].length - 1];
|
||||
|
||||
if (queue[msg.guild.id].length === 1) {
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setDescription(`now playing: **${song.titleFormat}**`)
|
||||
.setThumbnail(song.thumbnail)
|
||||
.setColor(embedColor)
|
||||
.setAuthor('foggy ♫', foggyImg);
|
||||
|
||||
msg.channel.send({embeds: [embed]});
|
||||
play(queue[msg.guild.id][0], msg.guild.id, connection, msg.channel);
|
||||
} else {
|
||||
let queueString = `queued: **${song.titleFormat}** _at position ${queue[msg.guild.id].length - 1}_`;
|
||||
if (q > 1) queueString = `queued **${q} songs** _at positions ${queue[msg.guild.id].length - q} - ${queue[msg.guild.id].length - 1}_`;
|
||||
|
||||
const embed = new Discord.MessageEmbed()
|
||||
.setDescription(queueString)
|
||||
.setColor(embedColor)
|
||||
.setAuthor('foggy ♫', foggyImg);
|
||||
msg.channel.send({embeds: [embed]});
|
||||
|
||||
if (!players[msg.guild.id] || players[msg.guild.id].state === Voice.AudioPlayerStatus.Idle || players[msg.guild.id].state === Voice.AudioPlayerStatus.Paused) {
|
||||
play(queue[msg.guild.id][0], msg.guild.id, connection, msg.channel);
|
||||
}
|
||||
for (const p of params.slice(1)) {
|
||||
await playOrQueue(p, msg.channel, msg);
|
||||
}
|
||||
} else if (cmd === 'search') {
|
||||
playOrQueue(p.slice(1), msg.channel, msg);
|
||||
} else if (cmd === 'skip' || cmd === 's') {
|
||||
const player = players[msg.guild.id];
|
||||
if (!player) return msg.channel.send('the bot isn\'t playing any music!');
|
||||
|
|
Reference in New Issue