How to use LavaLink on Glitch?


#1

Hello,

How can i setup an lavalink server? For my discord.js discord bot. i know how i can install it on a windows system.


#2

Hi @julianborghuis, take a look at this topic from a few months ago that discusses using lavalink in your glitch projects: I cannot install Lavalink. Looks like you have to add the .jar file and then run the command to start it in the console. The console can be accessed by clicking “Logs” at the top of your file tree. Hope this helps!


#3

Mhh yeah i have it already see. But you must set an ip adress. Must i set localhost? And, How start i the bot also i have the java already started? You can 1 job do on 1 project map. Or?? @lyzidiamond


#5

Check this: I will connect to the lavalink server via Glitch but also i do the command !play (yt link) He will lose connection:

`C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example>node .
[MUSIC_LOADCMD] Loaded play
[MUSIC_LOADCMD] Loaded remove
[MUSIC_LOADCMD] Loaded help
[MUSIC_LOADCMD] Loaded skip
[MUSIC_LOADCMD] Loaded leave
[MUSIC_LOADCMD] Loaded search
[MUSIC_LOADCMD] Loaded pause
[MUSIC_LOADCMD] Loaded resume
[MUSIC_LOADCMD] Loaded volume
[MUSIC_LOADCMD] Loaded queue
[MUSIC_LOADCMD] Loaded loop
[MUSIC_LOADCMD] Loaded clear
[MUSIC_LOADCMD] Loaded np
[LavalinkMusic] Running version 0.0.2
[LavalinkMusic] Running NodeJS v11.7.0
[LavalinkMusic] Running Discord.JS 11.3.2
[LavalinkMusic] Logged in as test music lavalink#6547 (ID 538035163662254140)
[LavalinkMusic] Listening to host billowy-egret.glitch.me and port 2333
[LavalinkMusic] Prefix: !
events.js:173
      throw er; // Unhandled 'error' event
      ^

Error: Unexpected server response: 502
    at ClientRequest.req.on (C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example\node_modules\discord.js-lavalink\node_modules\ws\lib\websocket.js:558:5)
    at ClientRequest.emit (events.js:188:13)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:562:21)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:113:17)
    at Socket.socketOnData (_http_client.js:449:20)
    at Socket.emit (events.js:188:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:145:17)
Emitted 'error' event at:
    at LavalinkNode.node.on.error (C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example\node_modules\discord.js-lavalink\src\lib\PlayerManager.js:70:47)
    at LavalinkNode.emit (events.js:188:13)
    at LavalinkNode._error (C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example\node_modules\discord.js-lavalink\src\lib\LavalinkNode.js:226:14)
    at WebSocket.emit (events.js:188:13)
    at abortHandshake (C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example\node_modules\discord.js-lavalink\node_modules\ws\lib\websocket.js:670:15)
    at ClientRequest.req.on (C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example\node_modules\discord.js-lavalink\node_modules\ws\lib\websocket.js:558:5)
    [... lines matching original stack trace ...]
    at Socket.socketOnData (_http_client.js:449:20)

C:\Users\Julian Borghuis\bot\discord.js-lavalink-musicbot-example>

MOD EDIT: formatting


#6

@julianborghuis
Add this event:

client.on("error", (error) => {
   console.error(error);
}); 

#7

i see no events.js or ClientRequest.emit


#8

But i cant diownload my own lavalink. why? Glitch uses an old java version


#9

Hey @julianborghuis, welcome to the Glitch Forums!

I don’t know much about LavaLink, so I might not be a ton of help here (I’m also going to move this over to the Discord Help category in case someone over there might be able to offer some better ideas). What @anon43389526 mentioned is definitely a good place to start - it might help figure out what the exact error is.

Aside from that, from your error message it seems like you might be trying to connect to your Glitch project over port 2333. That won’t work, since Glitch doesn’t open any external ports to anything other than 80 and 443. But I could be misunderstanding what I’m seeing there.

From looking at the logs in the project, it looks like LavaLink is using Tomcat under the covers, and is trying to open it on port 8080. That also won’t work, as Glitch only opens one local port to your project (it’s typically 3000, but changes under some circumstances; the PORT environment variable holds the currently-open port if you haven’t overwritten it; in Node you can get that from process.env.PORT).

Lastly, your project seems to be regularly bumping up against the CPU and memory limits of the project’s container. We currently don’t have a way for you to increase those, although we plan to release options for that sometime this year. That’s just something to keep in mind; if your project consistently goes over those limits it will be shut down.

Another thing to keep in mind - since your project never opens a listener on the open port Glitch doesn’t know that it’s finished starting up - we look for a listener on process.env.PORT to know when to stop trying to install your dependencies and start your project. Any server listening on that port will work, so you could move what you have in your package.json’s start script into a shell file and start a process there, or you can do it in node with something as simple as

const http = require('http');
http.createServer().listen(process.env.PORT);

It seems like a lot of the high CPU and memory are when the project starts LavaLink up, and that’s happening over and over again because of what I mentioned above.

Lastly, I’m not sure what you mean in your last message; it seems like you do have a version of LavaLink in the project, and aside from what I mentioned above it looks like its trying to start. Maybe you can clarify what you meant there?


#11

I think that a lavalink server on Glitch not a great plan is. Anyone that have a free alternative? Heroku is bad.