ManagerUtils
Defined in: src/structures/Utils.ts:46
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new ManagerUtils(LavalinkManager?: LavalinkManager): ManagerUtils;Defined in: src/structures/Utils.ts:48
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
LavalinkManager? | LavalinkManager |
Returns
Section titled “Returns”ManagerUtils
Properties
Section titled “Properties”| Property (defined in) | Type | Default value |
|---|---|---|
LavalinkManager (src/structures/Utils.ts:47) | LavalinkManager<Player> | undefined |
Methods
Section titled “Methods”buildPluginInfo()
Section titled “buildPluginInfo()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | any | - |
clientData | any | - |
Returns
Section titled “Returns”any
buildTrack()
Section titled “buildTrack()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | | Track | LavalinkTrack | - |
requester | unknown | - |
Returns
Section titled “Returns”buildUnresolvedTrack()
Section titled “buildUnresolvedTrack()”buildUnresolvedTrack(query: | UnresolvedTrack | UnresolvedQuery, requester: unknown): UnresolvedTrack;Defined in: src/structures/Utils.ts:128
Builds a UnresolvedTrack to be resolved before being played .
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
query | | UnresolvedTrack | UnresolvedQuery | - |
requester | unknown | - |
Returns
Section titled “Returns”extractSourceOfQuery()
Section titled “extractSourceOfQuery()”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends object |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
searchQuery | T | - |
Returns
Section titled “Returns”T
The updated searchQuery object with the extracted source and modified query string.
findSourceOfQuery()
Section titled “findSourceOfQuery()”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).
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
queryString | string | - |
Returns
Section titled “Returns”getClosestTrack()
Section titled “getClosestTrack()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | UnresolvedTrack | - |
player | Player | - |
Returns
Section titled “Returns”Promise<Track>
getTransformedRequester()
Section titled “getTransformedRequester()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
requester | unknown | - |
Returns
Section titled “Returns”unknown
isNode()
Section titled “isNode()”isNode(data: LavalinkNode): boolean;Defined in: src/structures/Utils.ts:167
Validate if a data is equal to a node
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | LavalinkNode | - |
Returns
Section titled “Returns”boolean
isNodeOptions()
Section titled “isNodeOptions()”isNodeOptions(data: LavalinkNodeOptions): boolean;Defined in: src/structures/Utils.ts:219
Validate if a data is equal to node options
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | LavalinkNodeOptions | - |
Returns
Section titled “Returns”boolean
isNotBrokenTrack()
Section titled “isNotBrokenTrack()”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:
Parameters
Section titled “Parameters”| Parameter | Type | Default value |
|---|---|---|
data | | UnresolvedTrack | Track | undefined |
minDuration | number | 29e3 |
Returns
Section titled “Returns”data is Track
Example
Section titled “Example”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()
Section titled “isTrack()”isTrack(data: | UnresolvedTrack | Track): data is Track;Defined in: src/structures/Utils.ts:290
Validate if a data is equal to a track
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
data | | UnresolvedTrack | Track | the Track to validate |
Returns
Section titled “Returns”data is Track
isUnresolvedTrack()
Section titled “isUnresolvedTrack()”isUnresolvedTrack(data: | UnresolvedTrack | Track): data is UnresolvedTrack;Defined in: src/structures/Utils.ts:300
Checks if the provided argument is a valid UnresolvedTrack.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | | UnresolvedTrack | Track |
Returns
Section titled “Returns”data is UnresolvedTrack
isUnresolvedTrackQuery()
Section titled “isUnresolvedTrackQuery()”isUnresolvedTrackQuery(data: UnresolvedQuery): boolean;Defined in: src/structures/Utils.ts:315
Checks if the provided argument is a valid UnresolvedTrack.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
data | UnresolvedQuery |
Returns
Section titled “Returns”boolean
transformLavaSearchQuery()
Section titled “transformLavaSearchQuery()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
query | LavaSearchQuery | - |
Returns
Section titled “Returns”| {
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()
Section titled “transformQuery()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
query | SearchQuery | - |
Returns
Section titled “Returns”object
| Name | Type | Default value | Defined in |
|---|---|---|---|
extraQueryUrlParams | any | undefined | src/structures/Utils.ts:515 |
query | string | query | src/structures/Utils.ts:514 |
source | SearchPlatform | typedDefault | src/structures/Utils.ts:516 |
typedLowerCase()
Section titled “typedLowerCase()”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 Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
T extends unknown |
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
input | T | - |
Returns
Section titled “Returns”T
validateQueryString()
Section titled “validateQueryString()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
node | LavalinkNode | - |
queryString | string | - |
sourceString? | SearchPlatform | - |
Returns
Section titled “Returns”void
validateSourceString()
Section titled “validateSourceString()”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.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
node | LavalinkNode | - |
sourceString | SearchPlatform | - |
Returns
Section titled “Returns”void