diff --git a/commands/music/nowplaying.js b/commands/music/nowplaying.js index 5031daf..caa0b05 100644 --- a/commands/music/nowplaying.js +++ b/commands/music/nowplaying.js @@ -29,6 +29,10 @@ class NowPlayingCommand extends MusicCommand { name: "💬 Channel:", value: this.channel.guild.channels.get(this.member.voiceState.channelID).name }, + { + name: "🌐 Node:", + value: player.node.name + }, { name: `${"▬".repeat(parts)}🔘${"▬".repeat(10 - parts)}`, value: `${format(player.position)}/${track.isStream ? "∞" : format(track.length)}` diff --git a/commands/music/queue.js b/commands/music/queue.js index ba216a9..bf4febf 100644 --- a/commands/music/queue.js +++ b/commands/music/queue.js @@ -11,7 +11,7 @@ class QueueCommand extends MusicCommand { if (!this.channel.guild.members.get(this.client.user.id).voiceState.channelID) return "I'm not in a voice channel!"; if (!this.channel.permissionsOf(this.client.user.id).has("embedLinks")) return "I don't have the `Embed Links` permission!"; const player = this.connection; - const node = nodes.filter((val) => { return val.name === player.player.node.name })[0]; + const node = nodes.filter((val) => val.name === player.player.node.name)[0]; const tracks = await fetch(`http://${node.url}/decodetracks`, { method: "POST", body: JSON.stringify(this.queue), headers: { Authorization: node.auth, "Content-Type": "application/json" } }).then(res => res.json()); const trackList = []; const firstTrack = tracks.shift(); @@ -41,6 +41,9 @@ class QueueCommand extends MusicCommand { }, { name: "🔁 Looping?", value: player.loop ? "Yes" : "No" + }, { + name: "🌐 Node", + value: player.node.name }, { name: "🗒️ Queue", value: value !== "del" ? value.join("\n") : "There's nothing in the queue!" diff --git a/utils/soundplayer.js b/utils/soundplayer.js index 09cd017..098d51e 100644 --- a/utils/soundplayer.js +++ b/utils/soundplayer.js @@ -31,7 +31,7 @@ export async function checkStatus() { } export async function connect(client) { - manager = new Shoukaku(new Connectors.Eris(client), nodes); + manager = new Shoukaku(new Connectors.Eris(client), nodes, { moveOnDisconnect: true, resume: true, reconnectInterval: 500, reconnectTries: 1 }); client.emit("ready"); // workaround manager.on("error", (node, error) => { logger.error(`An error occurred on Lavalink node ${node}: ${error}`); @@ -83,7 +83,8 @@ export async function play(client, sound, options, music = false) { response = await node.rest.resolve(sound); if (!response) return "🔊 I couldn't get a response from the audio server."; if (response.loadType === "NO_MATCHES" || response.loadType === "LOAD_FAILED") return "I couldn't find that song!"; - } catch { + } catch (e) { + logger.error(e); return "🔊 Hmmm, seems that all of the audio servers are down. Try again in a bit."; } const oldQueue = queues.get(voiceChannel.guild.id); @@ -144,6 +145,10 @@ export async function nextSong(client, options, connection, track, info, music, name: "💬 Channel:", value: voiceChannel.name }, + { + name: "🌐 Node:", + value: connection.node.name + }, { name: `${"▬".repeat(parts)}🔘${"▬".repeat(10 - parts)}`, value: `0:00/${info.isStream ? "∞" : format(info.length)}` @@ -161,6 +166,7 @@ export async function nextSong(client, options, connection, track, info, music, } } connection.removeAllListeners("exception"); + connection.removeAllListeners("stuck"); 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, shuffle, playMessage: playingMessage }); @@ -177,6 +183,7 @@ export async function nextSong(client, options, connection, track, info, music, } catch { // no-op } + connection.removeAllListeners("stuck"); connection.removeAllListeners("end"); players.delete(voiceChannel.guild.id); queues.delete(voiceChannel.guild.id); @@ -188,6 +195,11 @@ export async function nextSong(client, options, connection, track, info, music, await options.interaction.createMessage(content); } }); + connection.on("stuck", () => { + const nodeName = manager.getNode().name; + connection.move(nodeName); + connection.resume(); + }); connection.on("end", async (data) => { if (data.reason === "REPLACED") return; let queue = queues.get(voiceChannel.guild.id);