Fix a couple of sound player bugs
This commit is contained in:
parent
02a6e256b5
commit
0da673975b
2 changed files with 8 additions and 14 deletions
|
@ -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 AwaitRejoin from "../utils/awaitrejoin.js";
|
||||||
import { random } from "../utils/misc.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);
|
const connection = players.get(oldChannel.guild.id);
|
||||||
if (connection && oldChannel.id === connection.voiceChannel.id) {
|
if (connection && oldChannel.id === connection.voiceChannel.id) {
|
||||||
if (oldChannel.voiceMembers.filter((i) => i.id !== client.user.id && !i.bot).length === 0) {
|
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 waitMessage = await client.createMessage(connection.originalChannel.id, "🔊 Waiting 10 seconds for someone to return...");
|
||||||
const awaitRejoin = new AwaitRejoin(oldChannel, true);
|
const awaitRejoin = new AwaitRejoin(oldChannel, true);
|
||||||
awaitRejoin.on("end", async (rejoined, member) => {
|
awaitRejoin.on("end", async (rejoined, member) => {
|
||||||
if (rejoined) {
|
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 });
|
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.`);
|
waitMessage.edit(`🔊 ${member.mention} is the new voice channel host.`);
|
||||||
} else {
|
} else {
|
||||||
|
@ -22,9 +22,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await connection.player.stop(connection.originalChannel.guild.id);
|
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||||
await manager.leave(connection.originalChannel.guild.id);
|
|
||||||
await connection.player.destroy();
|
|
||||||
} catch {
|
} catch {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
@ -53,9 +51,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await connection.player.stop(connection.originalChannel.guild.id);
|
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||||
await manager.leave(connection.originalChannel.guild.id);
|
|
||||||
await connection.player.destroy();
|
|
||||||
} catch {
|
} catch {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
@ -72,9 +68,7 @@ export default async (client, cluster, worker, ipc, member, oldChannel) => {
|
||||||
});
|
});
|
||||||
} else if (member.id === client.user.id) {
|
} else if (member.id === client.user.id) {
|
||||||
try {
|
try {
|
||||||
await connection.player.stop(connection.originalChannel.guild.id);
|
connection.player.node.leaveChannel(connection.originalChannel.guild.id);
|
||||||
await manager.leave(connection.originalChannel.guild.id);
|
|
||||||
await connection.player.destroy();
|
|
||||||
} catch {
|
} catch {
|
||||||
// no-op
|
// no-op
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ export async function play(client, sound, options, music = false) {
|
||||||
const playlistTracks = response.playlistInfo.selectedTrack ? sortedTracks : [sortedTracks[0]];
|
const playlistTracks = response.playlistInfo.selectedTrack ? sortedTracks : [sortedTracks[0]];
|
||||||
queues.set(voiceChannel.guild.id, oldQueue ? [...oldQueue, ...playlistTracks] : playlistTracks);
|
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,
|
guildId: voiceChannel.guild.id,
|
||||||
channelId: voiceChannel.id,
|
channelId: voiceChannel.id,
|
||||||
shardId: voiceChannel.guild.shard.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("error");
|
||||||
connection.removeAllListeners("end");
|
connection.removeAllListeners("end");
|
||||||
connection.playTrack({ track });
|
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) => {
|
connection.once("exception", async (exception) => {
|
||||||
try {
|
try {
|
||||||
if (playingMessage.channel.messages.has(playingMessage.id)) await playingMessage.delete();
|
if (playingMessage.channel.messages.has(playingMessage.id)) await playingMessage.delete();
|
||||||
|
|
Loading…
Reference in a new issue