Skip to content

ManagerUtils

Defined in: src/structures/Utils.ts:46

new ManagerUtils(LavalinkManager?: LavalinkManager): ManagerUtils;

Defined in: src/structures/Utils.ts:48

ParameterType
LavalinkManager?LavalinkManager

ManagerUtils

Property (defined in)TypeDefault value
LavalinkManager
(src/structures/Utils.ts:47)
LavalinkManager<Player>undefined
buildPluginInfo(data: any, clientData?: any): any;

Defined in: src/structures/Utils.ts:58

Builds a pluginInfo object based on the provided data, extracting relevant information from the data and clientData parameters. This function is used to construct the pluginInfo property for tracks, allowing for consistent handling of plugin-related information across different track sources and formats.

ParameterTypeDescription
dataany-
clientDataany-

any


buildTrack(data:
| Track
| LavalinkTrack, requester: unknown): Track;

Defined in: src/structures/Utils.ts:71

Builds a Track object from the provided data and requester information. It validates the presence of required properties in the data, transforms the requester using a custom transformer function if provided, and constructs a Track object with the appropriate properties and plugin information. The function also includes error handling to ensure that the input data is valid and provides debug information if track building fails.

ParameterTypeDescription
data| Track | LavalinkTrack-
requesterunknown-

Track


buildUnresolvedTrack(query:
| UnresolvedTrack
| UnresolvedQuery, requester: unknown): UnresolvedTrack;

Defined in: src/structures/Utils.ts:128

Builds a UnresolvedTrack to be resolved before being played .

ParameterTypeDescription
query| UnresolvedTrack | UnresolvedQuery-
requesterunknown-

UnresolvedTrack


extractSourceOfQuery<T>(searchQuery: T): T;

Defined in: src/structures/Utils.ts:484

Extracts the source from the query if it starts with a valid source prefix (e.g., “ytsearch:”) and updates the searchQuery object accordingly.

Type Parameter
T extends object
ParameterTypeDescription
searchQueryT-

T

The updated searchQuery object with the extracted source and modified query string.


findSourceOfQuery(queryString: string): SearchPlatform;

Defined in: src/structures/Utils.ts:467

Finds the source of a query string by checking if it starts with a valid source prefix defined in the DefaultSources object. If a valid source prefix is found, it returns the corresponding SearchPlatform; otherwise, it returns null. This function is useful for determining the intended search platform for a given query string, allowing for more accurate search results when the user specifies a source (e.g., “ytsearch:Never Gonna Give You Up” would indicate that the search should be performed on YouTube).

ParameterTypeDescription
queryStringstring-

SearchPlatform


getClosestTrack(data: UnresolvedTrack, player: Player): Promise<Track>;

Defined in: src/structures/Utils.ts:325

Gets the closest track by resolving the provided UnresolvedTrack using the getClosestTrack function. It includes error handling to catch any exceptions that may occur during the resolution process and emits a debug event if the resolution fails. The function returns a Promise that resolves to a Track object if successful, or undefined if no closest track is found.

ParameterTypeDescription
dataUnresolvedTrack-
playerPlayer-

Promise<Track>


getTransformedRequester(requester: unknown): unknown;

Defined in: src/structures/Utils.ts:197

Gets the transformed requester based on the LavalinkManager options. If a custom requester transformer function is provided in the player options, it applies that function to the requester; otherwise, it returns the requester as is. The function also includes error handling to catch any exceptions that may occur during the transformation process and emits a debug event if the transformation fails.

ParameterTypeDescription
requesterunknown-

unknown


isNode(data: LavalinkNode): boolean;

Defined in: src/structures/Utils.ts:167

Validate if a data is equal to a node

ParameterTypeDescription
dataLavalinkNode-

boolean


isNodeOptions(data: LavalinkNodeOptions): boolean;

Defined in: src/structures/Utils.ts:219

Validate if a data is equal to node options

ParameterTypeDescription
dataLavalinkNodeOptions-

boolean


isNotBrokenTrack(data:
| UnresolvedTrack
| Track, minDuration?: number): data is Track;

Defined in: src/structures/Utils.ts:276

Validate tracks based on duration whether they are playble or broken tracks. most tracks should be longer than 30s, so you can put a minDuration of 29e3 (cause preview tracks are exactly 30s) or put 0. This check is not done automatically, you need to check it yourself by doing:

ParameterTypeDefault value
data| UnresolvedTrack | Trackundefined
minDurationnumber29e3

data is Track

const res = await player.search("Adele");
// short hand:
const validTracks = res.tracks.filter(client.lavalink.utils.isNotBrokenTrack)
// or with options:
const validTracks = res.tracks.filter(t => client.lavalink.utils.isNotBrokenTrack(t, 29e3));
// then you can add it to the queue.
await player.queue.add(validTracks);

isTrack(data:
| UnresolvedTrack
| Track): data is Track;

Defined in: src/structures/Utils.ts:290

Validate if a data is equal to a track

ParameterTypeDescription
data| UnresolvedTrack | Trackthe Track to validate

data is Track


isUnresolvedTrack(data:
| UnresolvedTrack
| Track): data is UnresolvedTrack;

Defined in: src/structures/Utils.ts:300

Checks if the provided argument is a valid UnresolvedTrack.

ParameterType
data| UnresolvedTrack | Track

data is UnresolvedTrack


isUnresolvedTrackQuery(data: UnresolvedQuery): boolean;

Defined in: src/structures/Utils.ts:315

Checks if the provided argument is a valid UnresolvedTrack.

ParameterType
dataUnresolvedQuery

boolean


transformLavaSearchQuery(query: LavaSearchQuery):
| {
extraQueryUrlParams: any;
query: never;
source: SearchPlatform;
types: any[];
}
| {
query: string;
source: | "ytsearch"
| "ytmsearch"
| "scsearch"
| "bcsearch"
| "spsearch"
| "sprec"
| "amsearch"
| "dzsearch"
| "dzisrc"
| "dzrec"
| "ymsearch"
| "ymrec"
| "vksearch"
| "vkrec"
| "tdsearch"
| "tdrec"
| "qbsearch"
| "qbisrc"
| "qbrec"
| "pdsearch"
| "pdisrc"
| "pdrec"
| "ftts"
| "speak"
| "phsearch"
| "pornhub"
| "porn"
| "tts"
| "jssearch"
| "jsrec"
| "local"
| "http"
| "https"
| "link"
| "uri"
| "youtube"
| "yt"
| "youtube music"
| "youtubemusic"
| "ytm"
| "musicyoutube"
| "music youtube"
| "soundcloud"
| "sc"
| "am"
| "apple music"
| "applemusic"
| "apple"
| "musicapple"
| "music apple"
| "sp"
| "spsuggestion"
| "spotify"
| "spotify.com"
| "spotifycom"
| "dz"
| "deezer"
| "yandex"
| "yandex music"
| "yandexmusic"
| "vk"
| "vk music"
| "vkmusic"
| "tidal"
| "tidal music"
| "qobuz"
| "pandora"
| "pd"
| "pandora music"
| "pandoramusic"
| "flowerytts"
| "flowery"
| "flowery.tts"
| "bandcamp"
| "bc"
| "js"
| "jiosaavn"
| "td";
types: string[];
};

Defined in: src/structures/Utils.ts:534

Transforms a LavaSearchQuery by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, the determined search platform to be used for the search operation, and the types of search (track, playlist, artist, album, text) to be performed.

ParameterTypeDescription
queryLavaSearchQuery-

| { extraQueryUrlParams: any; query: never; source: SearchPlatform; types: any[]; } | { query: string; source: | "ytsearch" | "ytmsearch" | "scsearch" | "bcsearch" | "spsearch" | "sprec" | "amsearch" | "dzsearch" | "dzisrc" | "dzrec" | "ymsearch" | "ymrec" | "vksearch" | "vkrec" | "tdsearch" | "tdrec" | "qbsearch" | "qbisrc" | "qbrec" | "pdsearch" | "pdisrc" | "pdrec" | "ftts" | "speak" | "phsearch" | "pornhub" | "porn" | "tts" | "jssearch" | "jsrec" | "local" | "http" | "https" | "link" | "uri" | "youtube" | "yt" | "youtube music" | "youtubemusic" | "ytm" | "musicyoutube" | "music youtube" | "soundcloud" | "sc" | "am" | "apple music" | "applemusic" | "apple" | "musicapple" | "music apple" | "sp" | "spsuggestion" | "spotify" | "spotify.com" | "spotifycom" | "dz" | "deezer" | "yandex" | "yandex music" | "yandexmusic" | "vk" | "vk music" | "vkmusic" | "tidal" | "tidal music" | "qobuz" | "pandora" | "pd" | "pandora music" | "pandoramusic" | "flowerytts" | "flowery" | "flowery.tts" | "bandcamp" | "bc" | "js" | "jiosaavn" | "td"; types: string[]; }


transformQuery(query: SearchQuery): object;

Defined in: src/structures/Utils.ts:510

Transforms a search query by determining the appropriate search platform based on the query string and the default search platform specified in the LavalinkManager options. It checks if the query string starts with a valid source prefix and extracts it if present. The function returns an object containing the modified query string, any extra URL parameters, and the determined search platform to be used for the search operation.

ParameterTypeDescription
querySearchQuery-

object

NameTypeDefault valueDefined in
extraQueryUrlParamsanyundefinedsrc/structures/Utils.ts:515
querystringquerysrc/structures/Utils.ts:514
sourceSearchPlatformtypedDefaultsrc/structures/Utils.ts:516

typedLowerCase<T>(input: T): T;

Defined in: src/structures/Utils.ts:499

Converts a string to lowercase if the input is a string, otherwise returns the input as is. This is useful for ensuring that search platform identifiers are case-insensitive while allowing other types of input to pass through unchanged.

Type Parameter
T extends unknown
ParameterTypeDescription
inputT-

T


validateQueryString(
node: LavalinkNode,
queryString: string,
sourceString?: SearchPlatform): void;

Defined in: src/structures/Utils.ts:348

Validates the query string against various criteria, including checking for empty strings, length limits for specific sources, blacklisted links or words, and ensuring that the Lavalink node has the necessary source managers enabled for the provided query. The function also includes debug event emissions to assist with troubleshooting and understanding the validation process.

ParameterTypeDescription
nodeLavalinkNode-
queryStringstring-
sourceString?SearchPlatform-

void


validateSourceString(node: LavalinkNode, sourceString: SearchPlatform): void;

Defined in: src/structures/Utils.ts:567

Validates the provided source string against the capabilities of the Lavalink node. It checks if the source string is supported by the node’s enabled source managers and plugins, throwing errors if any required sources or plugins are missing for the specified search platform. This ensures that search queries are only executed with compatible sources based on the node’s configuration.

ParameterTypeDescription
nodeLavalinkNode-
sourceStringSearchPlatform-

void