fixed music

This commit is contained in:
Emily 2020-04-22 19:00:57 +10:00
parent 6ee9122442
commit 98612a7784
3 changed files with 32 additions and 24 deletions

View file

@ -24,11 +24,13 @@ exports.run = async (client, message) => {
if (guild.queue.length < 1 || !guild.playing || !guild.dispatcher) return message.channel.send('Nothing is playing.')
if (!message.member.voice.channel) return message.channel.send('You need to be in voice channel to use this command!')
guild.dispatcher.end('silent')
guild.queue = []
guild.playing = false
guild.paused = false
guild.queue = []
guild.dispatcher.end('silent')
guild.dispatcher = null
guild.skippers = []
message.channel.send('Playback stopped!')
}

View file

@ -7,33 +7,32 @@ module.exports = (client, oldState, newState) => {
const guild = music.getGuild(newState.guild.id)
if (guild.playing && guild.voiceChannel.id === oldState.channelID) {
if (guild.voiceChannel.members.size === 1) {
if (guild.voiceChannel.members.filter(member => !member.user.bot).size < 1) {
guild.autoDisconnect = true
setTimeout(() => {
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
setTimeout(() => {
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
setTimeout(() => {
if (guild.voiceChannel.members.size === 1 && guild.autoDisconnect) {
guild.playing = false
guild.queue = []
guild.message.channel.send(`The music will end in 2 minutes if nobody rejoins **${guild.voiceChannel.name}**`)
.then(msg => {
msg.delete({ timeout: 120000 })
})
// Probably should be async? But no need here I think
guild.dispatcher.end('silent')
guild.message.channel.send('No one is listening to me. Leaving voice chat!')
} else {
guild.autoDisconnect = false
}
}, 30000)
} else {
guild.autoDisconnect = false
}
}, 20000)
setTimeout(() => {
if (guild.dispatcher !== null && guild.voiceChannel.members.filter(member => !member.user.bot).size < 1 && guild.autoDisconnect) {
// Probably should be async? But no need here I think
guild.dispatcher.end('silent')
guild.queue = []
guild.playing = false
guild.paused = false
guild.dispatcher = null
guild.skippers = []
guild.message.channel.send('The music has ended because no one was listening to me ;~;')
} else {
guild.autoDisconnect = false
}
}, 10000)
}, 120000)
} else {
guild.autoDisconnect = false
}
}
}

View file

@ -93,8 +93,11 @@ exports.play = async function (client, message, query, ignoreQueue) {
// Fix the bot if somehow broken
// music "playing", nothing in queue
if ((guild.playing || guild.dispatcher) && guild.queue.length === 0) {
guild.queue = []
guild.playing = false
guild.paused = false
guild.dispatcher = null
guild.skippers = []
// music not playing, something is in queue
} else if (!guild.playing && !guild.dispatcher && guild.queue.length > 0) {
guild.queue = []
@ -188,7 +191,11 @@ exports.play = async function (client, message, query, ignoreQueue) {
if (guild.queue.length > 0) {
exports.play(client, message, null, true)
} else {
guild.queue = []
guild.playing = false
guild.paused = false
guild.dispatcher = null
guild.skippers = []
connection.disconnect()
}