How to use rainlink?

Here, I will show you how to use rainlink in the simplest way possible.

Understanding the Driver

Driver in Rainlink is a class contain all basic communication function with lavalink/nodelink like WS/REST hadling.

The main features of driver is making a way to translate all current WS/REST api response to lavalink v4 api response. This will make Rainlink can run able on lavalink v3 and portable.

Currently, driver developing is not documented and supported. If you want, you can try.

This is the list of all rainlink driver currently supported (codename is made up by me)

Driver NameVoice ServerLanguageSupported VersionCodenameNotes
lavalink/v4/koinuLavalinkJavav4.0.0 - v4.x.xkoinu
lavalink/v3/kotoLavalinkJavav3.0.0 - v3.7.xkotofilter and resume in lavalink below v3.4 not supported
nodelink/v2/nariNodelinkJavascriptv2.0.0 - v2.x.xnariSome filter mode in nodelink not supported

Understanding the Structure

At the core of Rainlink is the Rainlink class, which serves as the primary interface for interacting with its features. This class encapsulates essential functionalities, including driver, plugin, player and node management, ensuring a cohesive experience for developers. Example of how to init Rainlink:

const rainlink = new Rainlink({
  library: new Library.DiscordJS(client),
  nodes: [{
    name: 'owo',
    host: 'localhost',
    port: 2333,
    auth: 'youshallnotpass',
    secure: false,
    // You don't have to add this properties if you're using lavalink v4.
    // If you use a version other than lavalink, you can refer to the Understanding the Driver section above
    driver: "lavalink/v4/koinu"
  }]
});

Player and Node Management

One of the key aspects of Rainlink is its modular approach to player and node management. By dividing responsibilities into distinct classes, such as RainlinkPlayer and NodeManager, Rainlink enhances clarity and organization within your application.

Players

Players represent entities responsible for audio playback within a specific context, such as a Discord server. The RainlinkPlayer class handles player-related operations, offering functions for retrieving existing players, creating new ones, and accessing player-specific functionalities.

Retrieving Players

To retrieve a player associated with a particular Discord server, you can use the get method:

<Rainlink>.players.get("myGuildIdDiscord")

Retrieving Players

To retrieve a player associated with a particular Discord server, you can use the get method:

<Rainlink>.players.get("myGuildIdDiscord")

Creating Players

Creating a new player involves specifying relevant parameters, such as the Discord guild ID, guild shard ID associated voice/text channels:

<Rainlink>.create({
  guildId: "id",
  textId: "voiceId",
  voiceId: "textId",
  shardId: "<your_guild_shard_id>" || 0
})

Using extended function

Because of using driver as structure, rainlink offer extended function from driver to extend the use of lavalink or any voice server. You can see more functions on Extended Functions category. Below is the example how to use it:

Player extended function:

const player = <Rainlink>.players.get("guild_id")
if (!player) return
const exFunc = player.functions.get("function_name")
if (!exFunc)
await exFunc(...some_args)

Driver extended function:

const node = <Rainlink>.nodes.get("node_name")
if (!node) return
const exFunc = node.functions.get("function_name")
if (!exFunc)
await exFunc(...some_args)

Node Management

Nodes are essential components in Moonlink responsible for handling audio streams and distributing workload efficiently. The RainlinkNode class facilitates node management operations, offering functionalities for adding, retrieving, and removing nodes.

Adding Nodes

To add a new node, you can use the add method, specifying parameters such as host, password, and port:

<Rainlink>.nodes.add({
  name: "example lavalink", // You can set whatever you want
  host: "example.com",
  port: 2333,
  auth: "securePassword",
  secure: false, // Set true if your lavalink have ssl
  // You don't have to add this properties if you're using lavalink v4.
  // About using lavalink v3.7.x, you can change to lavalink@3
  // About using nodelink v2, you can change to nodelink@2
  driver: "lavalink@4"
})

Retrieving Nodes

You can retrieve a node using identifier:

<Rainlink>.nodes.get("example lavalink")

Removing Nodes

You can remove a node using identifier:

<Rainlink>.nodes.remove("example lavalink")

Lavalink serves as a simplified audio playback server, functioning as both an API and a WebSocket server for manipulating audio streams. It interfaces with LavaPlayer, which manages audio sources and related functionalities. Additionally, it includes Koe, similar to @discordjs/voice, facilitating connections with Discord for audio transmission.