PrismarineJS/prismarine-viewer

Bot gets kicked and the viewer is still using the port

EnderHacker0 opened this issue · 1 comments

When the bot gets disconnected, the viewer is still using the port.
And when the bot reconnects, it says that the port is already in use and leaves the server.

i did it by adding this code:

// Check for kicks and closing the viewer while reconnecting in 10 secs
  bot.on('kicked', (reason) => {
    if (bot.viewer) {
        bot.viewer.close();
    }
    console.log(`${config['bot-account']['username']} has been kicked from ${config.server.ip}: ${reason}`);
    console.log('Reconnecting in 10 seconds...');
    setTimeout(createBot, 10000);
  });

also note that i used a custom config for this so you may need to modify this code.