You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

discord.js-lavalink

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

discord.js-lavalink

A discord.js lavalink client

3.0.1
latest
Source
npmnpm
Version published
Weekly downloads
14
-12.5%
Maintainers
1
Weekly downloads
 
Created
Source

Discord npm npm downloads NPM version Build Status Codacy Badge Open Source Love dependencies Status devDependencies Status NPM

A lavalink client for Discord.js

Documentation

mrjacz.github.io/discord.js-lavalink

Installation

For stable

# Using yarn
yarn add discord.js-lavalink

# Using npm
npm install discord.js-lavalink

For Development

# Using yarn
yarn add MrJacz/discord.js-lavalink

# Using npm
npm install MrJacz/discord.js-lavalink

Download from the CI server

Put an application.yml file in your working directory. Example

Run with java -jar Lavalink.jar

The issue tracker is for issues only

If you're having a problem with the module contact us in the Discord Server

Implementation

Start by creating a new PlayerManager passing an array of nodes and an object with user the client's user id and shards The total number of shards your bot is operating on.

const { PlayerManager } = require("discord.js-lavalink");

const nodes = [{ host: "localhost", port: 2333, password: "youshallnotpass" }];

const manager = new PlayerManager(client, nodes, {
    user: client.user.id, // Client id
    shards: shardCount // Total number of shards your bot is operating on
});

manager.on("error", (node, error) => {
    node; // is the node which the error is from
    error; // is the error;
});

Resolving tracks using LavaLink REST API

const fetch = require("node-fetch");
const { URLSearchParams } = require("url");

async function getSongs(search) {
    const node = client.player.nodes.first();

    const params = new URLSearchParams();
    params.append("identifier", search);

    return fetch(`http://${node.host}:${node.port}/loadtracks?${params}`, { headers: { Authorization: node.password } })
        .then(res => res.json())
        .then(data => data.tracks)
        .catch(err => {
            console.error(err);
            return null;
        });
}

getSongs("ytsearch:30 second song").then(songs => {
    // handle loading of the tracks somehow ¯\_(ツ)_/¯
});

Joining and Leaving channels

// Join
const player = await manager.join({
    guild: guildId, // Guild id
    channel: channelId, // Channel id
    host: "localhost" // lavalink host, based on array of nodes
});

await player.play(track); // Track is a base64 string we get from Lavalink REST API

player.once("error", error => console.error(error));
player.once("end", data => {
    if (data.reason === "REPLACED") return; // Ignore REPLACED reason to prevent skip loops
    // Play next song
});

// Leave voice channel and destory Player
await manager.leave(guildId); // Player ID aka guild id

For a proper example look at example/app.js

Keywords

bot

FAQs

Package last updated on 20 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts