Error using moonlink in deno

I'm trying to update my bot to use moonlink given issues I've been having with other libraries and I get the following error:
error: Uncaught (in promise) SyntaxError: Invalid protocol value
at new WebSocket (ext:deno_websocket/01_websocket.js:207:13)
at Node.connect (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/entities/Node.js:62:23)
at file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:28:18
at Map.forEach (<anonymous>)
at NodeManager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:27:20)
at Manager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/core/Manager.js:52:20)
at initLava (file:///home/blocks/Documents/BIDOME/imports/queue.tsx:436:8)
at file:///home/blocks/Documents/BIDOME/index.ts:152:8
at CommandClient.emit (https://jsr.io/@denosaurs/event/2.0.2/mod.ts:295:7)
at CommandClient.emit (https://jsr.io/@harmony/harmony/2.9.1/src/client/client.ts:419:18
error: Uncaught (in promise) SyntaxError: Invalid protocol value
at new WebSocket (ext:deno_websocket/01_websocket.js:207:13)
at Node.connect (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/entities/Node.js:62:23)
at file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:28:18
at Map.forEach (<anonymous>)
at NodeManager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/management/NodeManager.js:27:20)
at Manager.init (file:///home/blocks/Documents/BIDOME/node_modules/.deno/[email protected]/node_modules/moonlink.js/dist/src/core/Manager.js:52:20)
at initLava (file:///home/blocks/Documents/BIDOME/imports/queue.tsx:436:8)
at file:///home/blocks/Documents/BIDOME/index.ts:152:8
at CommandClient.emit (https://jsr.io/@denosaurs/event/2.0.2/mod.ts:295:7)
at CommandClient.emit (https://jsr.io/@harmony/harmony/2.9.1/src/client/client.ts:419:18
Any ideas on how to fix it?
8 Replies
Bloxs
BloxsOP•2d ago
I'm using the following code:
export const nodes = new Manager({
nodes: new Array(nodesCount).fill(undefined).map((_, i) => ({
host: Deno.env.get(`LAVALINK_${i + 1}_HOST`)!,
port: parseInt(Deno.env.get(`LAVALINK_${i + 1}_PORT`)!),
password: Deno.env.get(`LAVALINK_${i + 1}_PASSWORD`)!,
secure: Deno.env.get(`LAVALINK_${i + 1}_SECURE`) == "true",
identifier: Deno.env.get(`LAVALINK_${i + 1}_NAME`)!,
retryDelay: 60 * 1000,
})),
options: {
NodeLinkFeatures: true,
clientName: "Bidome/2.0.0"
},
sendPayload: async (guildID: string, payload: unknown) => {
const guild = await client.guilds.resolve(guildID);
if (guild == undefined) return;
const shard = client.shards.get(guild.shardID) as Gateway;
// deno-lint-ignore no-explicit-any
shard.send(JSON.parse(payload as any));
},
});
export const nodes = new Manager({
nodes: new Array(nodesCount).fill(undefined).map((_, i) => ({
host: Deno.env.get(`LAVALINK_${i + 1}_HOST`)!,
port: parseInt(Deno.env.get(`LAVALINK_${i + 1}_PORT`)!),
password: Deno.env.get(`LAVALINK_${i + 1}_PASSWORD`)!,
secure: Deno.env.get(`LAVALINK_${i + 1}_SECURE`) == "true",
identifier: Deno.env.get(`LAVALINK_${i + 1}_NAME`)!,
retryDelay: 60 * 1000,
})),
options: {
NodeLinkFeatures: true,
clientName: "Bidome/2.0.0"
},
sendPayload: async (guildID: string, payload: unknown) => {
const guild = await client.guilds.resolve(guildID);
if (guild == undefined) return;
const shard = client.shards.get(guild.shardID) as Gateway;
// deno-lint-ignore no-explicit-any
shard.send(JSON.parse(payload as any));
},
});
UnschooledGamer
UnschooledGamer•2d ago
Deno's inbuilt Websocket doesn't support headers that's the reason you receive that error. Options you have are: - poly-fill the Global Websocket with some libraries like ws or others. - use an unstable WebSocketStream API refer: https://questions.deno.com/m/1205621973657321534 - Wait for @1Lucas1.apk (better option ig)
Headers for WebSocket client - Deno
I need to connect Deno (as a client) to a WebSocket server that requires custom headers on connection. I can't seem to find any currently supported method to accomplish this since the WebSocket API only allows for the url and protocols parameters. Is there any known best practice to accomplish this?
1Lucas1.apk
1Lucas1.apk•2d ago
I always forget about the stability of Deno and Bun NO STABILITY, COMPATIBILITY
UnschooledGamer
UnschooledGamer•2d ago
Welcome to JS Ecosystem.
1Lucas1.apk
1Lucas1.apk•2d ago
How now for me it's 11h at night Tomorrow morning, I do a search to better understand these problems And I bring a solution And also check the bun
UnschooledGamer
UnschooledGamer•2d ago
It's 8:41 A.M for me and we're in the #help channel
1Lucas1.apk
1Lucas1.apk•2d ago
here is 23:12 Sleep Tomorrow, it is better, I think more clearly, with sleep is very bad Have a good day for you and sorry for the delay of the solution If you want to skip the direct solution of the package, you can find a package on the internet with webSocket working with headers, and put as a global until you do it in the package officially
Bloxs
BloxsOP•16h ago
Global polyfills don't work for my usecase because it breaks the discord api library im using, so unless there's a way I can only pass it to moonlink that doesn't work

Did you find this page helpful?