Giter Site home page Giter Site logo

erela.js's Introduction

Erela.js

An easy-to-use Lavalink client for NodeJS.

Discord Downloads Version GitHub Stars License

Documentation

Note: Some links do not work, I'll fix them when I can. The sidebar menu has the links that are broken.

You can find the documentation at http://projects.warhammer.codes/erelajs (this link does work)

Installation

npm install erela.js

Prerequisites

Download & install the Java runtime and download the Lavalink.jar file.

Note: Java v11 or newer is required to run the Lavalink.jar.

Getting Started

  • Create an application.yml file in your working directory and copy the example into the created file and edit it with your configuration.

  • Run the jar file by running java -jar Lavalink.jar in a Terminal window.

Example usage

Note: Discord.js is used in this example, but it does work with Eris with the same example.

// To install Discord.js and Erela.js, run:
// npm install discord.js erela.js
const { Client } = require("discord.js");
const { ErelaClient } = require("erela.js");

// Initialize the Discord.js Client instance and an array of nodes for Erela.js.
const client = new Client();
const nodes = [{
    host: "localhost",
    port: 2333,
    password: "youshallnotpass",
}]

// Ready event fires when the Discord.js client is ready.
// Use once so it only fires once.
client.once("ready", () => {
    console.log("I am ready!")
    // Initializes an Erela client with the Discord.js client and nodes.
    client.music = new ErelaClient(client, nodes);
    // Listens to events.
    client.music.on("nodeConnect", node => console.log("New node connected"));
    client.music.on("nodeError", (node, error) => console.log(`Node error: ${error.message}`));
    client.music.on("trackStart", (player, track) => player.textChannel.send(`Now playing: ${track.title}`));
    client.music.on("queueEnd", player => {
        player.textChannel.send("Queue has ended.")
        client.music.players.destroy(player.guild.id);
    });
});

client.on("message", async message => {
    if (message.content.startsWith("!play")) {
        const {
            voiceChannel
        } = message.member;
        // Note: for discord.js master you need to use
        // const { channel } = message.member.voice;

        // Spawns a player and joins the voice channel.
        const player = client.music.players.spawn({
            guild: message.guild,
            voiceChannel: voiceChannel,
            textChannel: message.channel,
        });

        // Searches Youtube with your query and the requester of the track(s).
        // Returns a SearchResult with tracks property.
        const res = await client.music.search(message.content.slice(6), message.author);

        // Adds the first track to the queue.
        player.queue.add(res.tracks[0]);
        message.channel.send(`Enqueuing track ${res.tracks[0].title}.`)

        // Plays the player (plays the first track in the queue).
        // The if statement is needed else it will play the current track again
        if (!player.playing) player.play();
    }
});

client.login("your token");

Andesite-node

Erela.js can work with andesite-node. For filters (other than equalizer) you have to extend Player and add methods for each filter.

const { Player } = require("erela.js");

class CustomPlayer extends Player {
    constructor(...args) {
        super(...args);
    }

    setTimescale(speed, pitch, rate) {
        this.node.send({
            op: "filters",
            guildId: this.guild.id,
            timescale: {
                speed,
                pitch,
                rate
            },
        });
    }
}

client.once("ready", () => {
    client.music = new ErelaClient(client, nodes, {
        player: CustomPlayer
    });
});

Author

๐Ÿ‘ค WarHammer414

erela.js's People

Contributors

anish-shobith avatar solaris9 avatar

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.