Skip to content

Shoukaku

Main Shoukaku class

Extends

Constructors

new Shoukaku()

new Shoukaku(
connector: Connector,
nodes: NodeOption[],
options: ShoukakuOptions): Shoukaku

Parameters

ParameterTypeDescription
connectorConnectorA Discord library connector
nodesNodeOption[]An array that conforms to the NodeOption type that specifies nodes to connect to
optionsShoukakuOptionsOptions to pass to create this Shoukaku instance

Returns

Shoukaku

Overrides

TypedEventEmitter<ShoukakuEvents>.constructor

Defined in

shoukaku/src/Shoukaku.ts:187

Properties

connections

readonly connections: Map<string, Connection>;

Voice connections being handled

Defined in

shoukaku/src/Shoukaku.ts:163


connector

readonly connector: Connector;

Discord library connector

Defined in

shoukaku/src/Shoukaku.ts:151


id

id: null | string;

Shoukaku instance identifier

Defined in

shoukaku/src/Shoukaku.ts:171


nodes

readonly nodes: Map<string, Node>;

Connected Lavalink nodes

Defined in

shoukaku/src/Shoukaku.ts:159


options

readonly options: Required<ShoukakuOptions>;

Shoukaku options

Defined in

shoukaku/src/Shoukaku.ts:155


players

readonly players: Map<string, Player>;

Players being handled

Defined in

shoukaku/src/Shoukaku.ts:167

Methods

addNode()

addNode(options: NodeOption): void

Add a Lavalink node to the pool of available nodes

Parameters

ParameterType
optionsNodeOption

Returns

void

Defined in

shoukaku/src/Shoukaku.ts:215


emit()

emit<K>(eventName: K, ...args: ShoukakuEvents[Extract<K, string>]): boolean

Synchronously calls each of the listeners registered for the event named eventName, in the order they were registered, passing the supplied arguments to each.

Returns true if the event had listeners, false otherwise.

import { EventEmitter } from 'node:events';
const myEmitter = new EventEmitter();
// First listener
myEmitter.on('event', function firstListener() {
console.log('Helloooo! first listener');
});
// Second listener
myEmitter.on('event', function secondListener(arg1, arg2) {
console.log(`event with parameters ${arg1}, ${arg2} in second listener`);
});
// Third listener
myEmitter.on('event', function thirdListener(...args) {
const parameters = args.join(', ');
console.log(`event with parameters ${parameters} in third listener`);
});
console.log(myEmitter.listeners('event'));
myEmitter.emit('event', 1, 2, 3, 4, 5);
// Prints:
// [
// [Function: firstListener],
// [Function: secondListener],
// [Function: thirdListener]
// ]
// Helloooo! first listener
// event with parameters 1, 2 in second listener
// event with parameters 1, 2, 3, 4, 5 in third listener

Type Parameters

Type Parameter
K extends symbol | keyof ShoukakuEvents

Parameters

ParameterType
eventNameK
argsShoukakuEvents[Extract<K, string>]

Returns

boolean

Inherited from

TypedEventEmitter.emit

Since

v0.1.26

Defined in

shoukaku/src/Utils.ts:21


getIdealNode()

getIdealNode(connection?: Connection): undefined | Node

Gets an ideal node based on the nodeResolver you provided

Parameters

ParameterTypeDescription
connection?ConnectionOptional connection class for ideal node selection, if you use it

Returns

undefined | Node

An ideal node for you to do things with

Defined in

shoukaku/src/Shoukaku.ts:203


joinVoiceChannel()

joinVoiceChannel(options: VoiceChannelOptions): Promise<Player>

Joins a voice channel

Parameters

ParameterType
optionsVoiceChannelOptions

Returns

Promise<Player>

The created player

Defined in

shoukaku/src/Shoukaku.ts:248


leaveVoiceChannel()

leaveVoiceChannel(guildId: string): Promise<void>

Leaves a voice channel

Parameters

ParameterTypeDescription
guildIdstringThe id of the guild you want to delete

Returns

Promise<void>

The destroyed / disconnected player or undefined if none

Defined in

shoukaku/src/Shoukaku.ts:284


off()

off<K>(eventName: K, listener: (...args: ShoukakuEvents[Extract<K, string>]) => void): this

Alias for emitter.removeListener().

Type Parameters

Type Parameter
K extends symbol | keyof ShoukakuEvents

Parameters

ParameterType
eventNameK
listener(…args: ShoukakuEvents[Extract<K, string>]) => void

Returns

this

Inherited from

TypedEventEmitter.off

Since

v10.0.0

Defined in

shoukaku/src/Utils.ts:17


on()

on<K>(eventName: K, listener: (...args: ShoukakuEvents[Extract<K, string>]) => void): this

Adds the listener function to the end of the listeners array for the event named eventName. No checks are made to see if the listener has already been added. Multiple calls passing the same combination of eventName and listener will result in the listener being added, and called, multiple times.

server.on('connection', (stream) => {
console.log('someone connected!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a

Type Parameters

Type Parameter
K extends symbol | keyof ShoukakuEvents

Parameters

ParameterTypeDescription
eventNameKThe name of the event.
listener(…args: ShoukakuEvents[Extract<K, string>]) => voidThe callback function

Returns

this

Inherited from

TypedEventEmitter.on

Since

v0.1.101

Defined in

shoukaku/src/Utils.ts:9


once()

once<K>(eventName: K, listener: (...args: ShoukakuEvents[Extract<K, string>]) => void): this

Adds a one-time listener function for the event named eventName. The next time eventName is triggered, this listener is removed and then invoked.

server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});

Returns a reference to the EventEmitter, so that calls can be chained.

By default, event listeners are invoked in the order they are added. The emitter.prependOnceListener() method can be used as an alternative to add the event listener to the beginning of the listeners array.

import { EventEmitter } from 'node:events';
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a

Type Parameters

Type Parameter
K extends symbol | keyof ShoukakuEvents

Parameters

ParameterTypeDescription
eventNameKThe name of the event.
listener(…args: ShoukakuEvents[Extract<K, string>]) => voidThe callback function

Returns

this

Inherited from

TypedEventEmitter.once

Since

v0.3.0

Defined in

shoukaku/src/Utils.ts:13


removeNode()

removeNode(name: string, reason: string): void

Remove a Lavalink node from the pool of available nodes

Parameters

ParameterTypeDefault valueDescription
namestringundefinedName of the node
reasonstring'Remove node executed'Reason of removing the node

Returns

void

Defined in

shoukaku/src/Shoukaku.ts:233