erela.js icon indicating copy to clipboard operation
erela.js copied to clipboard

Node Connection Query

Open arpanr opened this issue 4 years ago • 2 comments

Hi

If Manager is not connected to any node, player.create() throws "No available nodes." which is cool, but is there a way to catch this and try to connect to nodes, like init() again once before telling the server users that music nodes are down?

Thanks

arpanr avatar Jun 03 '21 09:06 arpanr

if(player && player.node && !player.node.connected) await player.node.connect()

Tomato6966 avatar Jul 23 '21 08:07 Tomato6966

Hi

If Manager is not connected to any node, or player.create() throws "No available nodes." which is cool, but is there a way to catch this and try to connect to nodes, like init() again once before telling the server users that music nodes are down?

Thanks

try...catch can handle throw exceptions.

try {
     <Player>.create(...);
} catch {
     console.log("Not connected.");
}

Using something like <Player>.connect() can cause the same issue, and if a lavalink server is not running or having issues while connecting, this trick won't going to work. You better wait until it connects to the node.

Or if you want explicitly handle this error, use nodejs build-in process API, process.on(..., (f) => cb(f)); https://nodejs.org/api/process.html

rilysh avatar Apr 07 '22 04:04 rilysh