Leave if no one is listening

This commit is contained in:
Lukáš H 2020-04-22 09:49:45 +02:00
parent 69815dbdf2
commit e7ed288139
No known key found for this signature in database
GPG Key ID: E07D6630DBC17195
2 changed files with 26 additions and 1 deletions

View File

@ -7,7 +7,31 @@ module.exports = (client, oldState, newState) => {
let guild = music.getGuild(newState.guild.id);
if(guild.playing && guild.voiceChannel.id == oldState.channelID) {
console.log(newState.id + ' left VC, in which Woomy is playing music');
if(guild.voiceChannel.members.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) {
// 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);
} else {
guild.autoDisconnect = false;
};
}, 10000);
};
};
}
}

View File

@ -66,6 +66,7 @@ exports.getVideoByQuery = async function (client, query) {
exports.play = async function (client, message, query, ignoreQueue) {
const guild = exports.getGuild(message.guild.id)
guild.message = message;
if (!message.member.voice.channel && !guild.voiceChannel) {
return message.reply('You have to be connected to a voice channel to use this command!')