SearchResult
Represents the result of a search query, containing the tracks found, the type of result (playlist, track, search), and potential errors.
The SearchResult class normalizes the response from the Lavalink loadTracks endpoint. It makes it easy to determine if the result was a single track, a playlist, a search result list, or an error.
Properties
Result Fields
Data returned from the search operation.
Data
The type of result: 'track', 'playlist', 'search', 'empty', or 'error'.
An array of Track objects found. Empty if no results or error.
The name of the playlist (if loadType is 'playlist').
Error details if loadType is 'error'.
Helpers
True if the result is a playlist.
True if the result is a single direct track link.
True if the result is a list of search results.
True if no tracks were found.
True if an error occurred during loading.
Handling Results
How to handle the different load types returned by a search.
const res = await manager.search({ query: "..." });
switch (res.loadType) {
case "track":
player.queue.add(res.tracks[0]);
break;
case "playlist":
console.log(`Loaded playlist: ${res.playlistName}`);
player.queue.add(res.tracks);
break;
case "search":
// Add the first result
player.queue.add(res.tracks[0]);
break;
case "empty":
console.log("No matches found.");
break;
case "error":
console.error("Load failed:", res.exception?.message);
break;
}