Star ✨ on GitHub

Connector

Abstract class for creating custom bridges between Moonlink.js and Discord libraries.

The Connector class handles the communication layer between Moonlink.js and your Discord library. It manages the flow of voice packets and initializes the manager when the client is ready.

Properties

Connector Properties

Internal state of the connector.

References

managerManager

The Manager instance attached to this connector.

Methods

setManager(manager)

Assigns the Moonlink Manager instance to the connector. This is called automatically by manager.use().

managerManager required

The Moonlink Manager instance.

Example
const connector = new MyCustomConnector();
connector.setManager(manager);

listen(client)

Abstract. Attaches event listeners to the Discord client. This method should handle the 'ready' event (to call manager.init) and raw packet events (to call manager.packetUpdate).

clientany required

The Discord library client instance.

Example
// Example implementation
public listen(client) {
    client.on("raw", (packet) => this.manager.packetUpdate(packet));
}

send(guildId, payload)

Abstract. Transmits a voice packet payload to the Discord Gateway for a specific guild.

guildIdstring required

The ID of the guild.

payloadany required

The JSON payload to send.

Example
// Example implementation
public send(guildId, payload) {
    const guild = this.client.guilds.get(guildId);
    guild.shard.send(payload);
}

Built-in: DiscordJs

new Connectors.DiscordJs()

The official implementation for the discord.js library.

Example
const { Connectors } = require('moonlink.js');

// Automatically handles:
// 1. client.once('clientReady') -> manager.init()
// 2. client.on('raw') -> manager.packetUpdate()
// 3. send() -> guild.shard.send()
manager.use(new Connectors.DiscordJs(), client);