update music to support playnext

This commit is contained in:
Emily 2020-04-29 20:59:58 +10:00
parent cfcdf359f5
commit caeeafa3bb
2 changed files with 15 additions and 8 deletions

View file

@ -12,12 +12,12 @@ exports.conf = {
exports.help = {
name: 'play',
category: 'Music',
description: 'Plays or adds to queue requested music.',
usage: 'play [query]',
parameters: '[query] - A query to find video by or a link to the video.'
description: 'Plays the song you request, or adds it to the queue.',
usage: 'playnext [song]',
parameters: '[song] - The name or youtube URL of the song you want to play.'
}
const { play } = require('../utils/music')
exports.run = async (client, message, args, level, data) => {
await play(client, data.guild.music, message, args.join(' '))
await play(client, data.guild.music, message, args.join(' '), false)
}

View file

@ -64,7 +64,7 @@ exports.getVideoByQuery = async function (client, query) {
}
}
exports.play = async function (client, data, message, query, ignoreQueue) {
exports.play = async function (client, data, message, query, playNext, ignoreQueue) {
const guild = exports.getGuild(message.guild.id)
guild.message = message
@ -162,8 +162,12 @@ exports.play = async function (client, data, message, query, ignoreQueue) {
}
// Add video to queue
if (playNext === true) {
guild.queue.splice(1, 0, { video: video, requestedBy: message.author })
} else {
guild.queue.push({ video: video, requestedBy: message.author })
}
}
// Figure out if the bot should add it to queue or play it right now
if (guild.playing) {
@ -172,7 +176,10 @@ exports.play = async function (client, data, message, query, ignoreQueue) {
guild.playing = true
guild.voiceChannel = vc
if (!guild.channel) {
guild.channel = message.channel
}
const connection = await vc.join()
@ -189,7 +196,7 @@ exports.play = async function (client, data, message, query, ignoreQueue) {
guild.playing = false
if (guild.queue.length > 0) {
exports.play(client, data, message, null, true)
exports.play(client, data, message, null, false, true)
} else {
guild.queue = []
guild.playing = false