Star ✨ on GitHub

Using Connectors (Discord.js)

Cleaner setup by letting a Connector handle init, raw packets, and send().

In the previous guide we wired Moonlink manually using:

  • send(guildId, payload)
  • client.on('raw', ...)
  • manager.init(client.user.id)

That manual wiring is great for learning, but for many projects you’ll prefer using a Connector.

What a Connector does

A Connector acts as the bridge between Moonlink and your Discord library.

With the official Discord.js connector, it typically handles:

  • calling manager.init(...) at the right time
  • forwarding raw voice packets automatically
  • implementing send() for you

Discord.js Connector example

const { Client, GatewayIntentBits } = require("discord.js");
const { Manager, Connectors } = require("moonlink.js");

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildVoiceStates,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

const manager = new Manager({
  nodes: [
    { host: "localhost", port: 2333, password: "youshallnotpass" }
  ]
});

// The connector attaches the necessary listeners internally
manager.use(new Connectors.DiscordJs(), client);

client.login("YOUR_TOKEN");