Star ✨ on GitHub

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

loadTypeLoadType

The type of result: 'track', 'playlist', 'search', 'empty', or 'error'.

tracksTrack[]

An array of Track objects found. Empty if no results or error.

playlistNamestring | undefined

The name of the playlist (if loadType is 'playlist').

exceptionobject | undefined

Error details if loadType is 'error'.

Helpers

isPlaylistboolean

True if the result is a playlist.

isTrackboolean

True if the result is a single direct track link.

isSearchboolean

True if the result is a list of search results.

isEmptyboolean

True if no tracks were found.

isErrorboolean

True if an error occurred during loading.

Handling Results

How to handle the different load types returned by a search.

Example
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;
}