Project Discussion

A thread for discussing #lavaclient & related stufff
91 Replies
viztea
vizteaOP16mo ago
Since Lavalink v4 is right around the corner I should probably start brainstorming some ideas for the new api
topi
topi16mo ago
*Since Lavalink V4 is here I should ...
viztea
vizteaOP16mo ago
Nodes & Clusters A Node is a connection to a single lavalink instance while a Cluster is a collection of Nodes, both Cluster & Node implement a shared interface named Client which is the public facing api.
const client = new Node({ ...options... })
= new Cluster([ "...", "..." ]);

await client.connect("<user id>");
const client = new Node({ ...options... })
= new Cluster([ "...", "..." ]);

await client.connect("<user id>");
Note: Instead of uri: string, options: ... you can just pass in a single object like in lavaclient v4.
Manage Players
// get player
const player = client.players.resolve("<guild id>");

// get player from cache or api request to /sessions/:sid/players/:g
const player = await client.players.fetch("<guild id>", force=boolean);

// create a player, however, the returned player makes no guarantee whether
// lavalink actually has a player for the given guild id
const player = client.players.create("<guild id");
// get player
const player = client.players.resolve("<guild id>");

// get player from cache or api request to /sessions/:sid/players/:g
const player = await client.players.fetch("<guild id>", force=boolean);

// create a player, however, the returned player makes no guarantee whether
// lavalink actually has a player for the given guild id
const player = client.players.create("<guild id");
Note: Similar to discord.js managers you can just access the underlying cache map via <Client>.players.cache
Player Usage
// listen to events
player.on("trackStart/End/Stuck/Failed", callback);
player.on("updated", callback);

// access voice methods/info
player.voice.latency
.connected

await player.voice.connect("<channel id>");
await player.voice.disconnect();

// access the api endpoints for this specific player.
await player.api.update({ ...request... });
await player.api.*

// or use convenience methods (similar to lavaclient v4)
await player.play(track, { ...options... });
await player.*
// listen to events
player.on("trackStart/End/Stuck/Failed", callback);
player.on("updated", callback);

// access voice methods/info
player.voice.latency
.connected

await player.voice.connect("<channel id>");
await player.voice.disconnect();

// access the api endpoints for this specific player.
await player.api.update({ ...request... });
await player.api.*

// or use convenience methods (similar to lavaclient v4)
await player.play(track, { ...options... });
await player.*
Other Discord Libraries Since lavaclient will be remaining as a discord-library agnostic library I will be creating some connector libraries for a quicker, more streamlined experience when using libraries like discord.js. Runtimes All of these changes will be brought to the deno client when lavaclient v5 drops @asszx @zapteryx @justapie06 @tijmenh. @ivioleti Sorry for the pings! Since all of you have created threads in this channel & remained in the server I wouldn't mind some feedback on this if you're still using my client :3 I will be mentioning the @lavaclient user from here on out so if you want more updates please use <id:customize> to give yourself the role
max
max16mo ago
heya i have no objections to any of the changes but i assume there'll be a more thorough document or readme indicating breaking changes between v4 and v5?
viztea
vizteaOP16mo ago
more than likely
max
max16mo ago
if yes then im fine with it 👍 looking forward to it as well
viztea
vizteaOP16mo ago
npm
lavalink-protocol
Type-safe validation for the Lavalink protocol.. Latest version: 1.0.0-rc.4, last published: 2 hours ago. Start using lavalink-protocol in your project by running npm i lavalink-protocol. There are 2 other projects in the npm registry using lavalink-protocol.
npm
lavalink-ws-client
Type-safe WebSocket client for Lavalink. Latest version: 1.0.0-rc.1, last published: 2 hours ago. Start using lavalink-ws-client in your project by running npm i lavalink-ws-client. There are no other projects in the npm registry using lavalink-ws-client.
npm
lavalink-api-client
Type-safe API client for Lavalink. Latest version: 1.0.0-rc.5, last published: 2 hours ago. Start using lavalink-api-client in your project by running npm i lavalink-api-client. There is 1 other project in the npm registry using lavalink-api-client.
viztea
vizteaOP16mo ago
@dastormer not sure if you still use lavaclient for StormBeatz but pinging you just in case and if you don't maybe some of those new packages will interest you once they're finished @lavaclient user Published the first alpha version since it works™️. However, some stuff hasn't been implemented yet since i'm tired asf 1. clustering 2. most node events API This is basically what will be released in v5. If you have any objections please send a constructive message :D Refer to types & this message for api usage: https://canary.discord.com/channels/323365823572082690/1137317796821336085/1137321192626335754 Installation https://www.npmjs.com/package/lavaclient/v/5.0.0-alpha.1 pnpm/npm install lavaclient@alpha yarn add lavaclient@alpha
DaStormer
DaStormer15mo ago
yep, still using lavaclient, thanks for the update i'll check it out soon
viztea
vizteaOP15mo ago
@lavaclient user Plugin Updates 2 new plugins are being added to the family (but i have yet to publish them) Simplified Filter Management Allows for easier filter management through "effects"
import { type PlayerEffect, load } from "@lavaclient/plugin-effects";

load()

const nightcore: PlayerEffect = {
id: "nightcore",
filters: {
timescale: { rate: 1.123456789 },
},
};

const slowed: PlayerEffect = {
id: "slowed",
filters: {
timescale: { rate: 0.75 },
},
};

// 1.
await player.effects.toggle(nightcore);

// 2.
await player.effects.toggle(slowed);
import { type PlayerEffect, load } from "@lavaclient/plugin-effects";

load()

const nightcore: PlayerEffect = {
id: "nightcore",
filters: {
timescale: { rate: 1.123456789 },
},
};

const slowed: PlayerEffect = {
id: "slowed",
filters: {
timescale: { rate: 0.75 },
},
};

// 1.
await player.effects.toggle(nightcore);

// 2.
await player.effects.toggle(slowed);
1. This will apply 'nightcore' and any previously toggled effects. 2. Since 'nightcore' and 'slowed' both use the timescale filter the plugin will automatically disable 'nightcore' and keep 'slowed' Better LavaSearch Integration Better API client integration with the LavaSearch plugin by Topi
import "@lavaclient/plugin-lavasearch/register";

// 1.
await node.api.loadSearch("spsearch:Odetari", "track", "artist", "album");

// 2.
await node.api.loadSearchOrNull("spsearch:Odetari", "track", "artist", "album");
import "@lavaclient/plugin-lavasearch/register";

// 1.
await node.api.loadSearch("spsearch:Odetari", "track", "artist", "album");

// 2.
await node.api.loadSearchOrNull("spsearch:Odetari", "track", "artist", "album");
1. Loads a LavaSearch result with tracks, artists, and albums. Throws an exception if nothing was found. 2. Does the same thing as 1 but returns null if nothing was found. Misc. - The queue plugin is also getting a rework. - If Topi finishes the LavaQueue lavalink plugin I may write an integration plugin Other Updates - Clustering has been implemented - LavalinkAPIClient has been renamed to LavalinkHTTPClient
max
max15mo ago
👍 lgtm
viztea
vizteaOP9mo ago
@lavaclient user https://www.npmjs.com/package/lavaclient/v/5.0.0-rc.1 lavalink-protocol & lavalink-api/ws-client all have 1.0 releases now, plugins are still a wip
npm
lavaclient
A simple, easy-to-use, and flexible lavalink client for node.js. Latest version: 4.1.1, last published: 2 years ago. Start using lavaclient in your project by running npm i lavaclient. There are no other projects in the npm registry using lavaclient.
Bloxs
Bloxs9mo ago
all of those errors are now fixed, now I just need to fix my play cmd as everythings broken :SadCat2:
viztea
vizteaOP9mo ago
oh and I want to add cluster-wide config for stuff like ws & api options @lavaclient user active v5 users i want to know if you've had any problems migrating or experienced any bugs/issues with the new api oh yeah react with the emoji if you read this message btw
max
max9mo ago
@gino i assume there's no way to use lavaclient v5 in conjunction with the queue plugin at this moment?
viztea
vizteaOP9mo ago
no but i can port it real quick
max
max9mo ago
ah that'd be great, i've finished migrating to lavaclient v5 but the only thing stopping it from working is the queue LOL
viztea
vizteaOP9mo ago
lavaclient & lavalink-protocol will get two new versions along side this port @lavaclient user released updates to some packages [email protected] switched from typed-emitter to tiny-typed-emitter so that plugins could add events [email protected] added mayStartNext object
max
max9mo ago
sick
viztea
vizteaOP9mo ago
and for those who use the queue plugin, an almost compatible port is available at @lavaclient/plugin-queue the 1.0 will use the new userData track field and have some general improvements
max
max9mo ago
👌 tysm
Bloxs
Bloxs9mo ago
you guys have it easy with pre made queue plugins, I had to make my own bad queue system
viztea
vizteaOP9mo ago
it's not even that good tbh
Bloxs
Bloxs9mo ago
probably better than mine
max
max9mo ago
@gino oh yeah is the spotify plugin gonna be made compatible too?
viztea
vizteaOP9mo ago
no use lavasrc
max
max9mo ago
👍
viztea
vizteaOP9mo ago
i might make a plugin like lavasrc for client side stuff if people don’t know java but it won’t have anything built in
max
max9mo ago
i've managed to get everything ported over, looks good so far but i'm just getting ERR_MODULE_NOT_FOUND for import '@lavaclient/plugin-queue/register'; now
viztea
vizteaOP9mo ago
:hmm: are you using esm?
max
max9mo ago
yup
viztea
vizteaOP9mo ago
that may be why i don't have esm exports
max
max9mo ago
ah i see
viztea
vizteaOP9mo ago
:ImDead: erm you can try to load it manually, there's a load export
max
max9mo ago
gotcha lemme give that a shot aight thanks man i think it worked but just some issues with my code now
viztea
vizteaOP9mo ago
why can't i delete that 💀 discord moment
redbuls81.py
redbuls81.py9mo ago
Did you solve this error?
viztea
vizteaOP9mo ago
.
max
max9mo ago
yea i did, idk whats up with my code now but the queue refuses to start hm
viztea
vizteaOP9mo ago
i didn't really do an extensive test, but I assumed everything was fine since this code worked
max
max9mo ago
ah wth ty for that LOL i was still using Node#createPlayer which was able to create the player but queue refused to start switching to PlayerManager#create fixed it
viztea
vizteaOP9mo ago
createplayer should be private ? well its marked as internal hmmmm maybe i should make it clearer that
max
max9mo ago
hmm im not sure, ts wasn't saying anything and it was still working but ty! works fine now i've ported to v5
viztea
vizteaOP9mo ago
well its public for people who want to change what player class is used but its only meant for internal use
max
max9mo ago
ah i see
viztea
vizteaOP9mo ago
iydmma, are you porting quaver?
max
max9mo ago
sorry i missed your message, yep i've been busy the past few months but i have some free time at the moment and youtube was constantly throwing errors for the last lavalink version so i upgraded lavalink and ported to lavaclient v5
viztea
vizteaOP9mo ago
https://github.com/ZPTXDev/Quaver/blob/master/src/lib/PlayerHandler.ts#L270-L273 lmao i should improve the effects api it's basically a port of @Keia Development's effect management stuff and I haven't had to explicitly "set" an effect's state
max
max9mo ago
LMFAO i was writing bandaid solutions at that point i just wanted to get everything working cuz quaver was non-functional for like 2 or 3 days at that point ahh i see, makes sense
viztea
vizteaOP9mo ago
wait i do allow explicitly oops ahahahaah that's funny ok
max
max9mo ago
LOL
viztea
vizteaOP9mo ago
i have no excuses then
max
max9mo ago
ahem it's alright i mean as long as it gets the job done i was planning to rewrite quaver for some time actually but never found the time for it
viztea
vizteaOP9mo ago
this is why everything is a release candidate rn
max
max9mo ago
mhm mhm makes sense
viztea
vizteaOP9mo ago
the client itself seems fine though
max
max9mo ago
yup, so far no issues whatsoever i think it's all good i like the better defined properties in v5 everything makes more sense
viztea
vizteaOP9mo ago
that was the goal :Tired: the new packages help a lot too, i spent quite a bit of time on the lavalink api, ws, and protocol packages everything is type-safe and validated at runtime
max
max9mo ago
i think the effort paid off, everything just works™️
viztea
vizteaOP9mo ago
now you just gotta fix the site
max
max9mo ago
yeah LOL i got an issue with that it's not really a code issue but rather cert issue also turns out i forgot to load the effects plugin in my port whoops fixed it and nightcore works but seems like bassboost isn't working
viztea
vizteaOP9mo ago
makes sense
max
max9mo ago
2024-03-14T08:35:08.860Z ERROR Quaver Unable to encode request body
LavalinkHTTPError: Unable to encode request body
at D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\endpoint\factory.js:42:19
at PlayerAPI.update (D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\api\player.js:33:51)
at Player.update (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:97:37)
at Player.setFilters (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:78:25)
at PlayerEffectManager.apply (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:51:27)
at PlayerEffectManager.toggle (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:39:20)
at PlayerHandler.bassboost (file:///D:/ZPTX%20Dev/Quaver/dist/lib/PlayerHandler.js:190:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (file:///D:/ZPTX%20Dev/Quaver/dist/commands/bassboost.js:26:26)
2024-03-14T08:35:08.860Z ERROR Quaver Unable to encode request body
LavalinkHTTPError: Unable to encode request body
at D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\endpoint\factory.js:42:19
at PlayerAPI.update (D:\ZPTX Dev\Quaver\node_modules\lavalink-api-client\dist\api\player.js:33:51)
at Player.update (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:97:37)
at Player.setFilters (D:\ZPTX Dev\Quaver\node_modules\lavaclient\dist\player.js:78:25)
at PlayerEffectManager.apply (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:51:27)
at PlayerEffectManager.toggle (D:\ZPTX Dev\Quaver\node_modules\@lavaclient\plugin-effects\dist\effects.js:39:20)
at PlayerHandler.bassboost (file:///D:/ZPTX%20Dev/Quaver/dist/lib/PlayerHandler.js:190:52)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Object.execute (file:///D:/ZPTX%20Dev/Quaver/dist/commands/bassboost.js:26:26)
hm
viztea
vizteaOP9mo ago
there are only 14 bands
viztea
vizteaOP9mo ago
GitHub
Quaver/src/lib/PlayerHandler.ts at master · ZPTXDev/Quaver
Simple-to-use music bot with features such as bass boost, nightcore, seek, search, and more. - ZPTXDev/Quaver
viztea
vizteaOP9mo ago
should be length: 9 :SmileyCat: runtime validation at work
max
max9mo ago
ah ty LOL
viztea
vizteaOP9mo ago
your logger could use some work i think the validation error is the error cause but it doesn't seem to have been rendered
max
max9mo ago
yeah i'll rework it in my rewrite as for this it's just that i'm using letsencrypt's certs and they renew every 3 months or so, i needa symlink the cert to quaver's container but that's not quite possible (at least from what i've tried) so yeah it's quite a pain im also sure there's way better ways for me to do what im doing but i have not had time to figure any of that out unfortunately
viztea
vizteaOP9mo ago
yeah fair that's why i use a reverse proxy that does it for me traefik my beloved
max
max9mo ago
i'll have to look into that sometime length 9 still didn't fix it tho hm strange
viztea
vizteaOP9mo ago
you build ?
max
max9mo ago
yep the js shows 9 too
viztea
vizteaOP9mo ago
my bad there are 15 bands 14 is the highest index :Lols:
max
max9mo ago
oh LOL hmm
max
max9mo ago
ah.
viztea
vizteaOP9mo ago
...(Array.from({ length: 10 }).map(
(_, i): { band: number; gain: number } => ({
band: i + 5,
gain: -0.05,
}),
)),
...(Array.from({ length: 10 }).map(
(_, i): { band: number; gain: number } => ({
band: i + 5,
gain: -0.05,
}),
)),
max
max9mo ago
yep that fixed it, thanks! not the first time i've messed that up 😔
viztea
vizteaOP9mo ago
:Nice:
redbuls81.py
redbuls81.py9mo ago
@lavaclient/plugin-lavasearch has esm support but I can't use the loadSearch function : interactionRun: guild.client.music.api.loadSearch is not a function
redbuls81.py
redbuls81.py9mo ago
Yes, I loaded it, but I cannot access the function.
require("@lavaclient/plugin-lavasearch/register");
const pluginQueue = require("@lavaclient/plugin-queue");
pluginQueue.load();
const pluginEffects = require("@lavaclient/plugin-effects");
pluginEffects.load();
require("@lavaclient/plugin-lavasearch/register");
const pluginQueue = require("@lavaclient/plugin-queue");
pluginQueue.load();
const pluginEffects = require("@lavaclient/plugin-effects");
pluginEffects.load();
viztea
vizteaOP9mo ago
one sec create a post
DaStormer
DaStormer3mo ago
@gino hey is there a migration guide or smthn for v5
viztea
vizteaOP3mo ago
not really but check the pins of this thread or the read me
Want results from more Discord servers?
Add your server