Node
Represents a Lavalink node
Extends
Constructors
new Node()
new Node(manager: Shoukaku, options: NodeOption): Node
Parameters
Parameter | Type | Description |
---|---|---|
manager | Shoukaku | Shoukaku instance |
options | NodeOption | Options on creating this node |
Returns
Overrides
TypedEventEmitter<NodeEvents>.constructor
Defined in
Properties
group?
readonly optional group: string;
Group in which this node is contained
Defined in
info
info: null | NodeInfo;
Information about lavalink node
Defined in
manager
readonly manager: Shoukaku;
Shoukaku class
Defined in
name
readonly name: string;
Name of this node
Defined in
reconnects
reconnects: number;
The number of reconnects to Lavalink
Defined in
rest
readonly rest: Rest;
Lavalink rest API
Defined in
sessionId
sessionId: null | string;
SessionId of this Lavalink connection (not to be confused with Discord SessionId)
Defined in
state
state: State;
The state of this connection
Defined in
stats
stats: null | Stats;
Statistics from Lavalink
Defined in
ws
ws: null | WebSocket;
Websocket instance
Defined in
Methods
connect()
connect(): void
Connect to Lavalink
Returns
void
Defined in
disconnect()
disconnect(code: number, reason?: string): void
Disconnect from Lavalink
Parameters
Parameter | Type | Description |
---|---|---|
code | number | Status code |
reason ? | string | Reason for disconnect |
Returns
void
Defined in
emit()
emit<K>(eventName: K, ...args: NodeEvents[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 listenermyEmitter.on('event', function firstListener() { console.log('Helloooo! first listener');});// Second listenermyEmitter.on('event', function secondListener(arg1, arg2) { console.log(`event with parameters ${arg1}, ${arg2} in second listener`);});// Third listenermyEmitter.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
Parameter | Type |
---|---|
eventName | K |
…args | NodeEvents [Extract <K , string >] |
Returns
boolean
Inherited from
Since
v0.1.26
Defined in
error()
error(error: Error): void
To emit error events easily
Parameters
Parameter | Type | Description |
---|---|---|
error | Error | error message |
Returns
void
Defined in
off()
off<K>(eventName: K, listener: (...args: NodeEvents[Extract<K, string>]) => void): this
Alias for emitter.removeListener()
.
Type Parameters
Type Parameter |
---|
K extends symbol | keyof ShoukakuEvents |
Parameters
Parameter | Type |
---|---|
eventName | K |
listener | (…args : NodeEvents [Extract <K , string >]) => void |
Returns
this
Inherited from
Since
v10.0.0
Defined in
on()
on<K>(eventName: K, listener: (...args: NodeEvents[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
Parameter | Type | Description |
---|---|---|
eventName | K | The name of the event. |
listener | (…args : NodeEvents [Extract <K , string >]) => void | The callback function |
Returns
this
Inherited from
Since
v0.1.101
Defined in
once()
once<K>(eventName: K, listener: (...args: NodeEvents[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
Parameter | Type | Description |
---|---|---|
eventName | K | The name of the event. |
listener | (…args : NodeEvents [Extract <K , string >]) => void | The callback function |
Returns
this
Inherited from
Since
v0.3.0