CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/reconnector.js
Views: 789
1
/*
2
* This example will automatically reconnect when it gets disconnected from the server.
3
*/
4
const mineflayer = require('mineflayer')
5
6
if (process.argv.length < 4 || process.argv.length > 6) {
7
console.log('Usage : node reconnector.js <host> <port> [<name>] [<password>]')
8
process.exit(1)
9
}
10
11
function createBot () {
12
const bot = mineflayer.createBot({
13
host: process.argv[2],
14
port: parseInt(process.argv[3]),
15
username: process.argv[4] ? process.argv[4] : 'reconnector',
16
password: process.argv[5]
17
})
18
19
bot.on('error', (err) => console.log(err))
20
bot.on('end', createBot)
21
}
22
23
createBot()
24
25