From 854cf12d6482ba5902fe44dbf1317f9c38709336 Mon Sep 17 00:00:00 2001 From: aki Date: Thu, 24 Apr 2025 00:52:16 +0800 Subject: [PATCH] fix(lavalink): Correct Lavalink connection URL format and update deprecated code --- src/index.js | 8 ++++---- src/structures/ShoukakuEvents.js | 9 +++++---- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index e001a82..67374a2 100644 --- a/src/index.js +++ b/src/index.js @@ -27,17 +27,17 @@ const client = new Client({ ], }); -// Define Shoukaku nodes +// Define Shoukaku nodes - fix the URL format to properly connect to Lavalink const Nodes = [ { name: 'lavalink', - url: `${process.env.LAVALINK_HOST || 'localhost'}:${process.env.LAVALINK_PORT || '2333'}/v4/websocket`, + url: `${process.env.LAVALINK_HOST || 'localhost'}:${process.env.LAVALINK_PORT || '2333'}`, auth: process.env.LAVALINK_PASSWORD || 'youshallnotpass', secure: process.env.LAVALINK_SECURE === 'true' } ]; -// Initialize Shoukaku +// Initialize Shoukaku with proper configuration client.shoukaku = new Shoukaku(new Connectors.DiscordJS(client), Nodes, { moveOnDisconnect: false, resume: true, @@ -46,7 +46,7 @@ client.shoukaku = new Shoukaku(new Connectors.DiscordJS(client), Nodes, { }); // Show the actual Lavalink connection details (without exposing the actual password) -logger.info(`Lavalink connection configured to: ${process.env.LAVALINK_HOST}:${process.env.LAVALINK_PORT}/v4/websocket (Password: ${process.env.LAVALINK_PASSWORD ? '[SET]' : '[NOT SET]'})`); +logger.info(`Lavalink connection configured to: ${process.env.LAVALINK_HOST}:${process.env.LAVALINK_PORT} (Password: ${process.env.LAVALINK_PASSWORD ? '[SET]' : '[NOT SET]'})`); // Collections for commands client.commands = new Collection(); diff --git a/src/structures/ShoukakuEvents.js b/src/structures/ShoukakuEvents.js index 7f2fc6d..ae98612 100644 --- a/src/structures/ShoukakuEvents.js +++ b/src/structures/ShoukakuEvents.js @@ -26,14 +26,14 @@ class MusicPlayer { } // Get Shoukaku node - const node = this.client.shoukaku.getNode(); + const node = this.client.shoukaku.options.nodeResolver(this.client.shoukaku.nodes); if (!node) { throw new Error('No available Lavalink nodes!'); } try { // Create a new connection to the voice channel - const connection = await node.joinChannel({ + const connection = await this.client.shoukaku.joinVoiceChannel({ guildId: guildId, channelId: voiceChannel, shardId: 0, @@ -56,7 +56,7 @@ class MusicPlayer { this.current = track; // Start playback - await this.connection.playTrack({ track: track.track }); + await this.connection.playTrack({ track: track.encoded }); this.playing = true; return this; @@ -207,7 +207,8 @@ class MusicPlayer { * @returns {Promise} Array of track objects */ async search({ query, requester }) { - const node = this.client.shoukaku.getNode(); + // Get the first available node + const node = this.client.shoukaku.options.nodeResolver(this.client.shoukaku.nodes); if (!node) throw new Error('No available Lavalink nodes!'); try {