From 0da673975b4cd984f8f236107b9ac0b0e694a2c9 Mon Sep 17 00:00:00 2001 From: Essem Date: Tue, 28 Jun 2022 20:36:32 -0500 Subject: [PATCH] Fix a couple of sound player bugs --- events/voiceChannelLeave.js | 18 ++++++------------ utils/soundplayer.js | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/events/voiceChannelLeave.js b/events/voiceChannelLeave.js index bce25bb..3212a81 100644 --- a/events/voiceChannelLeave.js +++ b/events/voiceChannelLeave.js @@ -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 } diff --git a/utils/soundplayer.js b/utils/soundplayer.js index d943504..54aa9b9 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -93,7 +93,7 @@ export async function play(client, sound, options, music = false) { const playlistTracks = response.playlistInfo.selectedTrack ? sortedTracks : [sortedTracks[0]]; queues.set(voiceChannel.guild.id, oldQueue ? [...oldQueue, ...playlistTracks] : playlistTracks); } - const connection = player && player.player ? player.player : await node.joinChannel({ + const connection = player && player.player && player.player.connection.state !== 3 ? player.player : await node.joinChannel({ guildId: voiceChannel.guild.id, channelId: voiceChannel.id, shardId: voiceChannel.guild.shard.id, @@ -163,7 +163,7 @@ export async function nextSong(client, options, connection, track, info, music, connection.removeAllListeners("error"); connection.removeAllListeners("end"); connection.playTrack({ track }); - players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: host, voiceChannel: voiceChannel, originalChannel: options.channel, loop: loop, shuffle: shuffle, playMessage: playingMessage }); + players.set(voiceChannel.guild.id, { player: connection, type: music ? "music" : "sound", host: host, voiceChannel: voiceChannel, originalChannel: options.channel, loop, shuffle, playMessage: playingMessage }); connection.once("exception", async (exception) => { try { if (playingMessage.channel.messages.has(playingMessage.id)) await playingMessage.delete();