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!');
|
if (!node) throw new Error('No available Lavalink nodes!');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Determine search type
|
// Determine search type and prepare the identifier string
|
||||||
let searchOptions = {};
|
let identifier;
|
||||||
if (query.startsWith('http')) {
|
if (query.startsWith('http')) {
|
||||||
// Direct URL
|
// Direct URL
|
||||||
searchOptions = { query };
|
identifier = query;
|
||||||
} else {
|
} else {
|
||||||
// Search with prefix
|
// Search with prefix (Lavalink handles ytsearch/ytmsearch automatically with the plugin)
|
||||||
searchOptions = { query: `ytsearch:${query}` };
|
// 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
|
// Perform the search using the identifier string
|
||||||
const result = await node.rest.resolve(searchOptions);
|
const result = await node.rest.resolve(identifier);
|
||||||
if (!result || result.loadType === 'error' || result.loadType === 'empty') {
|
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');
|
throw new Error(result?.exception?.message || 'No results found');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,4 +281,4 @@ module.exports = {
|
|||||||
return musicPlayer;
|
return musicPlayer;
|
||||||
},
|
},
|
||||||
musicPlayer
|
musicPlayer
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user