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
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().
The Moonlink Manager instance.
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).
The Discord library client instance.
// 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.
The ID of the guild.
The JSON payload to send.
// 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.
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);