Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PrismarineJS
GitHub Repository: PrismarineJS/mineflayer
Path: blob/master/examples/echo.js
9427 views
1
/*
2
* This is one of the simplest examples.
3
*
4
* We created a simple bot that echoes back everything that is said on chat.
5
*
6
* It's not very useful yet, but you can use this as a starting point
7
* to create your own bot.
8
*/
9
const mineflayer = require('mineflayer')
10
11
if (process.argv.length < 4 || process.argv.length > 6) {
12
console.log('Usage : node echo.js <host> <port> [<name>] [online?]')
13
process.exit(1)
14
}
15
16
const bot = mineflayer.createBot({
17
host: process.argv[2],
18
port: parseInt(process.argv[3]),
19
username: process.argv[4] ? process.argv[4] : 'echo',
20
auth: process.argv[5] ? 'microsoft' : 'offline'
21
})
22
23
bot.on('chat', (username, message) => {
24
if (username === bot.username) return
25
bot.chat(message)
26
})
27
28
bot.on('kicked', (reason) => {
29
console.log('I was kicked from the server: ' + reason)
30
})
31
32