Prerequisites
Note: Java v11 or newer is required to run the Lavalink.jar.
Npm:
npm install erela.js
Yarn:
yarn add erela.js
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 other libraries with the same example but with your library functions.
// To install Discord.JS and Erela.JS, run:// npm install discord.js erela.jsconst Client = ;const Manager Player = ; // Initialize the Discord.JS Client.const client = ; // Initiate the Manager with some options and listen to some events.clientmanager = // Pass an array of node. Note: You do not need to pass any if you are using the default values (ones shown below). nodes: host: "localhost" port: 2333 password: "youshallnotpass" // Auto plays tracks after one ends, defaults to "false". autoPlay: true // A send method to send data to the Discord WebSocket using your library. // Getting the shard for the guild and sending the data to the WebSocket. { const guild = clientguildscache; if guild guildshard; }// You must handle moves by yourself, by default Erela.JS will not change the voice channel.; // Ready event fires when the Discord.JS client is ready.// Use EventEmitter#once() so it only fires once.client; // Here we send voice data to lavalink whenever the bot joins a voice channel to play audio in the channel.client; client; client;
Extending
Erela.JS can expand on its functionality by extending its classes. Note: This should only used if you are adding your own functions.
const Structure = ; // Use the extend method to extend the class.Structure; // Usage:const player = ;playerqueue;
Plugins
Erela.JS can expand on its functionality with plugins. Note: This should only be used if you want to use others functions.
// Only for demonstration.const Manager = ;const SaveQueue = ; const manager = plugins: max: 10 // Usage.const player = ;playerqueue;
Creating your own plugin
const Structure Plugin = ; Structure; moduleexports = // Use the constructor to pass values to the plugin. { // Able to use "max" as a option. thisoptions = options; } {}
Contributors
Note:
This code is here only personal purpose, not giving support for the changes i made here , all the credits belong Solaris a.k.a WarHammer414 the creator.