ManagerUtils

Utils you can use on the Manager side, for Tracks and other things!

ype: class

Constructor

new LavalinkManager(options:ManagerOptions)

Import

index.ts
import { ManagerUtils } from "lavalink-client";

Overview


Properties

.LavalinkManager

The provided Manager

Type: LavalinkManager | null

Methods

.buildTrack(data: LavalinkTrack|Track, requester:any)

Builds a Lavalink Track Response to a Client-Track.

If no Manager was proivided to the Util Manager, then manager#playerOptions#requestTransformer can't be used.

Returns: Track

const LavalinkTrack = await player.node.request("/loadtracks?identifier=dQw4w9WgXcQ");
const ClientTrack = client.lavalink.utils.buildTrack(LavalinkTrack, interaction.user);

.buildUnresolvedTrack(data:UnresolvedQuery|UnresolvedTrack, requester:any)

Builds an unresolved Track of a UnresolvedQuery / Track.

If no Manager was proivided to the Util Manager, then manager#playerOptions#requestTransformer can't be used.

Returns: UnresolvedTrack

const UnresolvedTrackQuery = { 
  // you can also do { info: { title, author } }
  title: "Never gonna give you up", 
  author: "Rick Astley"
}
const UnresolvedTrack = client.lavalink.utils.buildUnresolvedTrack(UnresolvedTrackQuery, interaction.user);

.isNode(data:LavalinkNode)

Checks if provided data is a Lavalink Node.

Returns: boolean

if(!client.lavalink.utils.isNode(player?.node))
 throw new Error("player.node is not a valid node")

.isNodeOptions(data:LavalinkNodeOptions)

Checks if provided data is a Lavalink Node Options Object.

Returns: boolean

if(!client.lavalink.utils.isNodeOptions({
  host: "localhost", port: 999999, // it will say false cause:
  // authorization is missing + port is invalid
}))
 throw new Error("player.node is not a valid node")

.isTrack(data:Track)

Checks if provided data is a Client Track Object.

Returns: boolean

if(!client.lavalink.utils.isTrack(yourData))
 throw new Error("Provided data is not a Track")

.isUnresolvedTrack(data:UnresolvedTrack)

Checks if provided data is a Client UnresolvedTrack Object.

Returns: boolean

if(!client.lavalink.utils.isUnresolvedTrack(yourData))
 throw new Error("Provided data is not an unresolved Track")

.isUnresolvedTrackQuery(data:UnresolvedQuery)

Checks if provided data is a UnresolvedQuery Object.

Returns: boolean

if(!client.lavalink.utils.isUnresolvedTrackQuery(yourData))
 throw new Error("Provided data is not an unresolved Track Query Object")

.getClosestTrack(data:UnresolvedTrack, player: Player)

Try's to find the Closest Track possible of an unresovled Track

if Unresolved track has encoded: it will try to decode it

If unresolved Track has uri / isrc it will try to search by that

Returns: Promise<Track | undefined>

const unresolvedTrack = client.lavalink.utils.buildUnresolved({ title: "Never Gonna Give you up" }, interaction.user);
const closest = await client.lavalink.utils.getClosestTrack(unresolvedTrack, player);
player.queue.add(closest);
// note you can also add unresolved tracks to the queue, the queue will automatically try to resolve it, when it's time to play it.
// you can also run await unresolvedTrack.resolve(); to resolve the track

.validateQueryString(node: LavalinkNode, data:string)

Checks if the query string contains a link and checks the followings:

  • If its source is enabled on the provided node

  • If managerOptions#validLinks is provided, it also checks for those

Returns: boolean

if(!client.lavalink.utils.validateQueryString(player.node, "https://www.youtube.com/watch?v=dQw4w9WgXcQ"))
 throw new Error("Can't use that link, cause the source of it is disabled on lavalink")

.validateSourceString(node: LavalinkNode, data:SearchPlatform)

Checks if SearchPlatform is useable, by checking if the source is enabled on the provided node

Returns: boolean

if(!client.lavalink.utils.validateSourceString(player.node, "youtube"))
 throw new Error("Can't use that source, cause it's disabled on lavalink")

Last updated