Skip to main content

YukinoClient API

The YukinoClient class is the main entry point for interacting with Yukino. It integrates with Discord.js and manages connections to one or more Lavalink nodes.

See the Types Reference for enums, interfaces, and advanced type definitions used throughout Yukino.

Constructor​

constructor(client: Client, options: ConnectorOptions, nodeOptions: NodeOptions | NodeOptions[])

Parameters​

  • client: Discord.js Client instance
  • options: ConnectorOptions for configuring the connection
  • nodeOptions: NodeOptions or NodeOptions[] for configuring one or more Lavalink nodes

Example (Single Node)​

import { Client } from 'discord.js';
import { YukinoClient } from 'yukinojs';

const client = new Client({/* ... */});
const yukino = new YukinoClient(client, {
client,
auth: 'your-password',
debug: true
}, {
name: 'main',
url: 'localhost:2333',
auth: 'your-password'
});

Example (Multiple Nodes)​

const yukino = new YukinoClient(client, connectorOptions, [
{ name: 'main', url: 'localhost:2333', auth: 'your-password' },
{ name: 'backup', url: 'localhost:2444', auth: 'your-password' }
]);

Properties​

connector​

  • Type: Connector
  • Description: The connector instance used for voice state management

nodeManager​

  • Type: NodeManager
  • Description: The manager for all Lavalink nodes

playerManager​

  • Type: PlayerManager
  • Description: The manager for all players

players​

  • Type: Map<string, Player>
  • Description: Map of all active players, keyed by guild ID (Read-only)

nodes​

  • Type: Map<string, Node>
  • Description: Map of all Lavalink nodes (Read-only)

idealNode​

  • Type: Node | undefined
  • Description: The ideal node for load balancing (Read-only)

isReady​

  • Type: boolean
  • Description: Whether any Lavalink node is connected and ready (Read-only)

Methods​

connect()​

  • Returns: void
  • Description: Connects to all configured Lavalink nodes

addNode(options: NodeOptions)​

  • Returns: Node
  • Description: Adds a single Lavalink node

addNodes(optionsArray: NodeOptions[])​

  • Returns: Node[]
  • Description: Adds multiple Lavalink nodes

setNodeSelector(fn: (nodes: Node[], guildId?: string) => Node | undefined)​

  • Returns: void
  • Description: Sets a custom node selection function for load balancing

createPlayer(options: PlayerOptions)​

  • Returns: Player
  • Description: Creates a new player for a guild. Throws if no node is ready.

getPlayer(guildId: string)​

  • Returns: Player | undefined
  • Description: Gets an existing player for a guild

hasPlayer(guildId: string)​

  • Returns: boolean
  • Description: Checks if a guild has a player

getQueue(guildId: string)​

  • Returns: Queue | undefined
  • Description: Gets the queue for a guild's player

loadTrack(query: string, options?: SearchOptions)​

  • Returns: Promise<LoadTrackResponse>
  • Description: Loads a track or playlist from a URL or search query

destroyPlayer(guildId: string)​

  • Returns: Promise<boolean>
  • Description: Destroys a specific player by guild ID

destroyAllPlayers()​

  • Returns: Promise<number>
  • Description: Destroys all players

getLavaStats()​

  • Returns: LavalinkStats
  • Description: Gets statistics for all Lavalink nodes

destroy()​

  • Returns: void
  • Description: Destroys all players and disconnects from all nodes

Events​

Events are emitted through the node manager and player manager. Example:

yukino.nodeManager.on('nodeReady', (node) => {
console.log(`Connected to Lavalink node: ${node.options.name}`);
});

yukino.playerManager.on('trackStart', (player, track) => {
console.log(`Now playing: ${track.info.title}`);
});

See Node Events and Player Events for a complete list.

Type Definitions​

ConnectorOptions​

interface ConnectorOptions {
client: Client;
auth: string;
debug?: boolean;
name?: string;
host?: string;
port?: number | string;
url?: string;
secure?: boolean;
version?: string;
sessionId?: string;
}

NodeOptions​

interface NodeOptions {
name: string;
url: string;
auth: string;
secure?: boolean;
group?: string;
reconnectInterval?: number;
reconnectTries?: number;
resumeKey?: string | null;
resumeTimeout?: number;
version?: string;
debug?: boolean;
}

PlayerOptions​

interface PlayerOptions {
guildId: string;
voiceChannelId: string;
textChannelId?: string;
deaf?: boolean;
mute?: boolean;
volume?: number;
queueOptions?: QueueOptions;
}

TypeScript Integration​

YukinoClient adds type definitions to Discord.js's Client:

declare module 'discord.js' {
interface Client {
yukino: YukinoClient;
}
}

Debug Mode​

When debug is enabled in the options:

  • Connection state changes are logged
  • Track loading information is displayed
  • Voice state updates are tracked
  • Errors are logged with stack traces

Example with debug enabled:

const yukino = new YukinoClient(client, {
client,
auth: 'password',
debug: true // Enable debug logging
}, {
name: 'main',
url: 'localhost:2333',
auth: 'password'
});