fixed voiceStateUpdate voiceWebSocket error.

This commit is contained in:
Matte 2021-01-21 14:05:22 +02:00
parent 46b3119f79
commit ff49fbd16c

View File

@ -1,46 +1,66 @@
module.exports = { module.exports = {
name: 'voiceStateUpdate', name: "voiceStateUpdate",
async execute(client, oldState, newState) { async execute(client, oldState, newState) {
if (oldState.channel === null) return; if (oldState.channel === null) return;
let change = false; let change = false;
const radio = client.radio.get(newState.guild.id); const radio = client.radio.get(newState.guild.id);
if (!radio) return; if (!radio) return;
/*
if (newState.member.id === client.user.id && oldState.member.id === client.user.id) {
if (newState.channel === null) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
return client.radio.delete(newState.guild.id);
}
const newPermissions = newState.channel.permissionsFor(newState.client.user); if (
if (!newPermissions.has('CONNECT') || !newPermissions.has('SPEAK') || !newPermissions.has('VIEW_CHANNEL')) { newState.member.id === client.user.id &&
try { oldState.member.id === client.user.id
const connection = await oldState.channel.join(); ) {
return radio.connection = connection; if (newState.channel === null) {
} catch (error) { client.funcs.statisticsUpdate(client, newState.guild, radio);
client.funcs.statisticsUpdate(client, newState.guild, radio); return client.radio.delete(newState.guild.id);
radio.connection.dispatcher.destroy(); }
radio.voiceChannel.leave();
client.radio.delete(oldState.guild.id); const newPermissions = newState.channel.permissionsFor(
return; newState.client.user
} );
} if (
if (newState.channel !== radio.voiceChannel) { !newPermissions.has("CONNECT") ||
change = true; !newPermissions.has("SPEAK") ||
radio.voiceChannel = newState.channel; !newPermissions.has("VIEW_CHANNEL")
radio.connection = newState.connection; ) {
} try {
}*/ setTimeout(
if (oldState.channel.members.size === 1 && oldState.channel === radio.voiceChannel || change) { async () => (radio.connection = await oldState.channel.join()),
setTimeout(() => { 1000
if (!radio || !radio.connection.dispatcher || !radio.connection.dispatcher === null) return; );
if (radio.voiceChannel.members.size === 1) { } catch (error) {
client.funcs.statisticsUpdate(client, newState.guild, radio); client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection.dispatcher.destroy(); radio.connection.dispatcher.destroy();
radio.voiceChannel.leave(); radio.voiceChannel.leave();
client.radio.delete(newState.guild.id); client.radio.delete(oldState.guild.id);
}
}, 120000);
} }
return;
}
if (newState.channel !== radio.voiceChannel) {
change = true;
radio.voiceChannel = newState.channel;
radio.connection = await newState.channel.join();
}
} }
if (
(oldState.channel.members.size === 1 &&
oldState.channel === radio.voiceChannel) ||
change
) {
setTimeout(() => {
if (
!radio ||
!radio.connection.dispatcher ||
!radio.connection.dispatcher === null
)
return;
if (radio.voiceChannel.members.size === 1) {
client.funcs.statisticsUpdate(client, newState.guild, radio);
radio.connection.dispatcher.destroy();
radio.voiceChannel.leave();
client.radio.delete(newState.guild.id);
}
}, 120000);
}
},
}; };