discord.js-lavalink
An alternative version of Discord.js-Lavalink, That is 100% compatible with latest Discord.js master commits but not compatible with Discord.js stable.
This branch mostly resolves the issues from the original branch and optimizes most of its functions hopefully.
This build has changes from its original version. Refer on docs to see what are in this library.
returns Promise<>
on documentation.
This version has breaking changes from 2.5.1, which is most of the functions returns a promise now. Make sure you update your code accordingly. Methods that returns a promise will have Installing this build is as easy as
- Add the code below in codeblock on your package.json "dependencies" section
"discord.js-lavalink-fork": "Deivu/discord.js-lavalink"
-
Do
npm i
-
Or you can install it via
npm i discord.js-lavalink-fork
-
Read Server Configuration part of README which is in HERE
-
OPEN YOUR PORTS Never forget
-
Done, Cheers!
Library Documentation
Example Code on using this
const { Client } = require("discord.js");
const { PlayerManager } = require("discord.js-lavalink-fork");
const fetch = require("node-fetch");
const lavalink_server = [{
host: "localhost",
port: 69,
region: "USA",
password: "OwO_sees_your_bulges"
}];
Client.on("ready", () => {
console.log("Qt Bot Now Online");
Client.lavalink = new PlayerManager(Client, lavalink_server, {
user: Client.user.id,
shards: Client.shard ? Client.shard.count : 1
});
});
Client.on("message", async (message) => {
if (message.content === "play") {
if (!Client.lavalink.has(message.guild.id)) {
const connection = await Client.lavalink.join({
guild: message.guild.id,
channel: message.member.voice.channel.id,
host: "localhost"
});
const server = lavalink_server[0];
const req = await fetch(`http://${server.host}:${server.port}/loadtracks?identifier=${encodeURIComponent("https://www.youtube.com/watch?v=aCinJZQTGmc")}`, {
headers: {
Authorization: server.password
}
});
const data = await req.json();
console.log(data);
const player = await connection.play(data.track);
player.once("end", async () => {
if (end.reason === "REPLACED") return;
await Client.lavalink.leave(message.guild.id);
await message.channel.send("Ended Playback");
});
await message.channel.send("Now Playing Moosik");
if (!req.ok) return;
}
}
})
Client.login("Lewd_Token");
If you wonder how to enable lavalink resuming of sessions with this lib, just call the PlayerManager with resume key set to true like how its shown below
const { PlayerManager } = require("discord.js-lavalink-fork");
const lavalink = new PlayerManager(Client, lavalink_server, {
user: 'your_bot_id',
shards: your_shard_count,
resume: true
});
// optional, you can listen to your node's reconnect disconnect events.
for (const node of lavalink.nodes.values()) {
node.on('reconnecting', (node) => console.log(node + ' is reconnecting'));
node.on('resumed', (node) => console.log(node + ' was able to resume its session'));
}
Listening for reset event to prevent leaks just incase your connection cannot be resumed anymore.
const connection = lavalink.join({
guild: message.guild.id,
channel: message.member.voice.channel.id,
host: "localhost"
});
const interval = setInterval(() => console.log('owo'), 1000)
connection.play(base64_track_from_lavalink_api).then((player) => {
player.once('reset', (raw) => {
clearInterval(interval);
lavalink.leave(message.guild.id).catch(console.error);
console.error(raw);
});
});
If you need more help about using this library.
Ask in #Bot Support in Here
This lavalink build is made for "Discord.js Latest Master Branch"
Based on MrJacz/discord.js-lavalink
which is originally created by: Jacz