Skip to content

Connectors

Lavalink plays the audio, but Discord only tells your bot where to connect. A connector does three things:

  1. Sends opcode 4 (join/leave voice) to the right shard.
  2. Forwards raw gateway events (VOICE_STATE_UPDATE, VOICE_SERVER_UPDATE, GUILD_CREATE, …) to raya.handleRaw().
  3. Calls raya.init(botUserId) once Discord is ready.
const { Raya, Connectors } = require('raya.js');
const raya = new Raya({
nodes,
connector: new Connectors.DiscordJS(client), // before client.login()
});

A connector is any object with attach and send. Add getToken to enable voice channel status without passing a token.

import type { Connector, Raya } from 'raya.js';
class MyConnector implements Connector {
constructor(private client: MyClient) {}
attach(raya: Raya) {
this.client.on('raw', (packet) => raya.handleRaw(packet));
this.client.once('ready', () => raya.init(this.client.user.id));
}
send(guildId: string, payload) {
this.client.shardFor(guildId).send(payload);
}
getToken() {
return this.client.token;
}
}