Skip to content

execaman/discolink

Repository files navigation

🎯 Purpose

The goal of this library is to abstract away obvious steps involved in the process of acting as an intermediary between Lavalink and Discord to give developers a cleaner yet intuitive interface to work with.

⚙️ Requirements

  • Runtime - one of the following:
  • Library - any gateway client that supports:
    • sending raw payloads over the connection
    • receiving raw payloads from the connection
  • Lavalink - at least with the following configuration:
    • disabled local tracks - for unique track identifiers
    • disabled built-in youtube source utilising their plugin instead (recommended)

🕓 Configuration

Any gateway client library meeting the requirements above is supported, you can apply the following pseudocode (this is the basic approach):

import { Client } from "main-lib";
import { Player } from "discolink";

const client = new Client(...);

const player = new Player({
  nodes: [], // add your nodes
  async forwardVoiceUpdate(guildId, payload) {
    // send the given payload to your gateway connection
    client.guilds.cache.get(guildId).shard.send(payload);
  }
});

client.on("raw", (payload) => {
  // call the handler on gateway dispatch
  player.voices.handleDispatch(payload);
});

client.login();

📝 Implementation

  • Handle track end reasons other than cleanup and finished
  • Handle voice states with care, e.g. reconnecting, changingNode, etc.
  • Handle queue destruction/relocation, e.g. guild/channel delete, node close/disconnect, etc.