Fix a couple of sound player bugs

This commit is contained in:
Essem 2022-06-11 15:23:41 -05:00
parent e211ddf5b9
commit 046b1d7f28
No known key found for this signature in database
GPG key ID: 7D497397CC3A2A8C
2 changed files with 13 additions and 4 deletions

View file

@ -4,7 +4,7 @@ import { players, queues } from "../utils/soundplayer.js";
class MusicCommand extends Command { class MusicCommand extends Command {
constructor(client, cluster, worker, ipc, options) { constructor(client, cluster, worker, ipc, options) {
super(client, cluster, worker, ipc, options); super(client, cluster, worker, ipc, options);
if (this.channel) { if (this.channel.guild) {
this.connection = players.get(this.channel.guild.id); this.connection = players.get(this.channel.guild.id);
this.queue = queues.get(this.channel.guild.id); this.queue = queues.get(this.channel.guild.id);
} }

View file

@ -152,7 +152,6 @@ export async function nextSong(client, options, connection, track, info, music,
connection.removeAllListeners("error"); connection.removeAllListeners("error");
connection.removeAllListeners("end"); connection.removeAllListeners("end");
await connection.play(track); await connection.play(track);
await connection.volume(75);
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: loop, shuffle: shuffle, playMessage: playingMessage });
connection.once("error", async (error) => { connection.once("error", async (error) => {
try { try {
@ -172,7 +171,12 @@ export async function nextSong(client, options, connection, track, info, music,
players.delete(voiceChannel.guild.id); players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id);
logger.error(error); logger.error(error);
await (options.type === "classic" ? options.channel.createMessage : options.interaction.createMessage)(`🔊 Looks like there was an error regarding sound playback:\n\`\`\`${error.type}: ${error.error}\`\`\``); const content = `🔊 Looks like there was an error regarding sound playback:\n\`\`\`${error.type}: ${error.error}\`\`\``;
if (options.type === "classic") {
await client.createMessage(options.channel.id, content);
} else {
await options.interaction.createMessage(content);
}
}); });
connection.on("end", async (data) => { connection.on("end", async (data) => {
if (data.reason === "REPLACED") return; if (data.reason === "REPLACED") return;
@ -213,7 +217,12 @@ export async function nextSong(client, options, connection, track, info, music,
players.delete(voiceChannel.guild.id); players.delete(voiceChannel.guild.id);
queues.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id);
skipVotes.delete(voiceChannel.guild.id); skipVotes.delete(voiceChannel.guild.id);
if (music) await (options.type === "classic" ? options.channel.createMessage : options.interaction.createMessage)("🔊 The current voice channel session has ended."); const content = "🔊 The current voice channel session has ended.";
if (options.type === "classic") {
await client.createMessage(options.channel.id, content);
} else {
await options.interaction.createMessage(content);
}
try { try {
if (playingMessage.channel.messages.has(playingMessage.id)) await playingMessage.delete(); if (playingMessage.channel.messages.has(playingMessage.id)) await playingMessage.delete();
if (player && player.playMessage.channel.messages.has(player.playMessage.id)) await player.playMessage.delete(); if (player && player.playMessage.channel.messages.has(player.playMessage.id)) await player.playMessage.delete();