Fix a couple of sound player bugs

This commit is contained in:
Essem 2022-06-28 20:36:32 -05:00
parent 02a6e256b5
commit 0da673975b
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 8 additions and 14 deletions

View file

@ -1,4 +1,4 @@
import { players, manager, queues, skipVotes } from "../utils/soundplayer.js";
import { players, queues, skipVotes } from "../utils/soundplayer.js";
import AwaitRejoin from "../utils/awaitrejoin.js";
import { random } from "../utils/misc.js";
@ -7,12 +7,12 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
const connection = players.get(oldChannel.guild.id);
if (connection && oldChannel.id === connection.voiceChannel.id) {
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
await connection.player.pause(true);
connection.player.setPaused(true);
const waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
const awaitRejoin = new AwaitRejoin(oldChannel, true);
awaitRejoin.on("end", async (rejoined, member) => {
if (rejoined) {
await connection.player.pause(false);
connection.player.setPaused(false);
players.set(connection.voiceChannel.guild.id, { player: connection.player, type: connection.type, host: member.id, voiceChannel: connection.voiceChannel, originalChannel: connection.originalChannel, loop: connection.loop, shuffle: connection.shuffle, playMessage: connection.playMessage });
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
} else {
@ -22,9 +22,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
// no-op
}
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
} catch {
// no-op
}
@ -53,9 +51,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
// no-op
}
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
} catch {
// no-op
}
@ -72,9 +68,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
});
} else if (member.id === client.user.id) {
try {
await connection.player.stop(connection.originalChannel.guild.id);
await manager.leave(connection.originalChannel.guild.id);
await connection.player.destroy();
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
} catch {
// no-op
}