GithubHelp home page GithubHelp logo

serhann / discord.js-lavalink Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mrjacz/discord.js-lavalink

0.0 1.0 0.0 364 KB

A discord.js lavalink client

Home Page: https://mrjacz.github.io/discord.js-lavalink/

License: MIT License

JavaScript 97.22% Shell 2.78%

discord.js-lavalink's Introduction

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

discord.js-lavalink

A Discord.js lavalink client

Documentation

mrjacz.github.io/discord.js-lavalink

Installation

For stable npm install discord.js-lavalink

For Development npm install mrjacz/discord.js-lavalink

LavaLink configuration

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: 80, region: "asia", 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
});

Resolving tracks using LavaLink REST API

async function getSongs(string) {
    const res = await snekfetch.get(`http://localhost:2333/loadtracks?identifier=${string}`)
        .set("Authorization", "youshallnotpass")
        .catch(err => {
            console.error(err);
            return null;
        });
    if (!res) throw "There was an error, try again";
    if (!res.body.length) throw "No tracks found";
    return res.body;
}

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

Joining and Leaving channels

// Join
manager.join({
    guild: guildId // Guild id
    channel: channelId // Channel id
    host: "localhost" // lavalink host, based on array of nodes
}).then(player => {
    player.play(track); // Track is a base64 string we get from Lavalink REST API

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

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

For a proper example look at Testing/app.js

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.