Get Started

First steps to get started

Overview

First you have to install the package into your project

๐Ÿ‘‰ via NPM
npm install --save lavalink-client

Dev Version: (Current)

npm install tomato6966/lavalink-client
๐Ÿ‘‰ via YARN
yarn add lavalink-client

Dev Version: (Current)

yarn add tomato6966/lavalink-client

Then you have to create the Manager

index.ts
import { LavalinkManager } from "lavalink-client";
import { Client, GatewayIntentBits } from "discord.js";

// create bot client
const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildVoiceStates
    ]
}) as Client & { lavalink: LavalinkManager }; 

// create lavalink client
client.lavalink = new LavalinkManager({
    nodes: [
        { // Important to have at least 1 node
            authorization: "yourverystrongpassword",
            host: "localhost",
            port: 2333,
            id: "testnode"
        }
    ],
    sendToShard: (guildId, payload) =>
        client.guilds.cache.get(guildId)?.shard?.send(payload),
    client: {
        id: process.env.CLIENT_ID,
        username: "TESTBOT",
    },
    // everything down below is optional
    autoSkip: true,
    playerOptions: {
        clientBasedPositionUpdateInterval: 150,
        defaultSearchPlatform: "ytmsearch",
        volumeDecrementer: 0.75,
        //requesterTransformer: requesterTransformer,
        onDisconnect: {
            autoReconnect: true, 
            destroyPlayer: false 
        },
        onEmptyQueue: {
            destroyAfterMs: 30_000, 
            //autoPlayFunction: autoPlayFunction,
        }
    },
    queueOptions: {
        maxPreviousTracks: 25
    },
});

Initialize the Manager and listen to the raw Event

Play Songs

How to add more features?

If you want to display things like "started playing a track", "queue ended", check out all possible events!

Important! Before creating a player, make sure that at least 1 node is connected to the lavalink node

Last updated