From 74cac2bfbbf3cfd7f64f7262e9537100f974c7f0 Mon Sep 17 00:00:00 2001 From: aki Date: Thu, 24 Apr 2025 01:22:19 +0800 Subject: [PATCH] fix(lavalink): Refactor search method to use identifier string for track resolution --- src/structures/ShoukakuEvents.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/structures/ShoukakuEvents.js b/src/structures/ShoukakuEvents.js index ae98612..c50a57d 100644 --- a/src/structures/ShoukakuEvents.js +++ b/src/structures/ShoukakuEvents.js @@ -212,19 +212,22 @@ class MusicPlayer { if (!node) throw new Error('No available Lavalink nodes!'); try { - // Determine search type - let searchOptions = {}; + // Determine search type and prepare the identifier string + let identifier; if (query.startsWith('http')) { // Direct URL - searchOptions = { query }; + identifier = query; } else { - // Search with prefix - searchOptions = { query: `ytsearch:${query}` }; + // Search with prefix (Lavalink handles ytsearch/ytmsearch automatically with the plugin) + // identifier = `ytsearch:${query}`; // Prefix might not be needed with the plugin, let Lavalink decide + identifier = query; // Pass the raw query for non-URLs } - // Perform the search - const result = await node.rest.resolve(searchOptions); + // Perform the search using the identifier string + const result = await node.rest.resolve(identifier); if (!result || result.loadType === 'error' || result.loadType === 'empty') { + // Log the identifier for debugging if search fails + logger.debug(`Search failed for identifier: ${identifier}`); throw new Error(result?.exception?.message || 'No results found'); } @@ -278,4 +281,4 @@ module.exports = { return musicPlayer; }, musicPlayer -}; \ No newline at end of file +};