fix(lavalink): Correct Lavalink connection URL format and update deprecated code

This commit is contained in:
Jose Daniel G. Percy 2025-04-24 00:52:16 +08:00
parent e54c23cc63
commit 854cf12d64
2 changed files with 9 additions and 8 deletions

View File

@ -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 = [ const Nodes = [
{ {
name: 'lavalink', 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', auth: process.env.LAVALINK_PASSWORD || 'youshallnotpass',
secure: process.env.LAVALINK_SECURE === 'true' secure: process.env.LAVALINK_SECURE === 'true'
} }
]; ];
// Initialize Shoukaku // Initialize Shoukaku with proper configuration
client.shoukaku = new Shoukaku(new Connectors.DiscordJS(client), Nodes, { client.shoukaku = new Shoukaku(new Connectors.DiscordJS(client), Nodes, {
moveOnDisconnect: false, moveOnDisconnect: false,
resume: true, 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) // 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 // Collections for commands
client.commands = new Collection(); client.commands = new Collection();

View File

@ -26,14 +26,14 @@ class MusicPlayer {
} }
// Get Shoukaku node // Get Shoukaku node
const node = this.client.shoukaku.getNode(); const node = this.client.shoukaku.options.nodeResolver(this.client.shoukaku.nodes);
if (!node) { if (!node) {
throw new Error('No available Lavalink nodes!'); throw new Error('No available Lavalink nodes!');
} }
try { try {
// Create a new connection to the voice channel // Create a new connection to the voice channel
const connection = await node.joinChannel({ const connection = await this.client.shoukaku.joinVoiceChannel({
guildId: guildId, guildId: guildId,
channelId: voiceChannel, channelId: voiceChannel,
shardId: 0, shardId: 0,
@ -56,7 +56,7 @@ class MusicPlayer {
this.current = track; this.current = track;
// Start playback // Start playback
await this.connection.playTrack({ track: track.track }); await this.connection.playTrack({ track: track.encoded });
this.playing = true; this.playing = true;
return this; return this;
@ -207,7 +207,8 @@ class MusicPlayer {
* @returns {Promise<Array>} Array of track objects * @returns {Promise<Array>} Array of track objects
*/ */
async search({ query, requester }) { 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!'); if (!node) throw new Error('No available Lavalink nodes!');
try { try {