fix(lavalink): Refactor search method to use identifier string for track resolution
This commit is contained in:
parent
bb7a796cf9
commit
74cac2bfbb
@ -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
|
||||
};
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user