PrismarineJS / mineflayer

Create Minecraft bots with a powerful, stable, and high level JavaScript API.
https://prismarinejs.github.io/mineflayer/
MIT License
5.1k stars 921 forks source link

TypeError [ERR_INVALID_ARG_TYPE] #2832

Closed Gyanbu closed 2 years ago

Gyanbu commented 2 years ago

Versions

Detailed description of a problem

I tried echo example program but it didn't work. It runs on raspberrypi 4. Bot connects to server and falls when i break block beneath him but when i type anything in chat he crashes instantly

Your current code


const mineflayer = require('mineflayer')

const bot = mineflayer.createBot({
  host: '192.168.0.11', // minecraft server ip
  username: 'bot', // minecraft username
  // password: '12345678' // minecraft password, comment out if you want to log into online-mode=false servers
  port: 4431,                // only set if you need a port that isn't 25565
  // version: false,             // only set if you need a specific version or snapshot (ie: "1.8.9" or "1.16.5"), otherwise it's set automatically
  // auth: 'mojang'              // only set if you need microsoft auth, then set this to 'microsoft'
})

bot.on('chat', (username, message) => {
  console.log('test')
  if (username === bot.username) return
  bot.chat(message)
})

// Log errors and kick reasons:
bot.on('kicked', console.log)
bot.on('error', console.log)

Error message

gyanbu@pi:~/cave_bot $ node bot.js

node:buffer:740
    throw new ERR_INVALID_ARG_TYPE(
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "string" argument must be of type string or an instance of Buffer or ArrayBuffer. Received undefined
    at new NodeError (node:internal/errors:393:5)
    at Function.byteLength (node:buffer:740:11)
    at sizeOfPString (/home/gyanbu/cave_bot/node_modules/protodef/src/datatypes/utils.js:127:25)
    at concat (/home/gyanbu/cave_bot/node_modules/minecraft-protocol/src/transforms/binaryStream.js:11:45)
    at client.verifyMessage (/home/gyanbu/cave_bot/node_modules/minecraft-protocol/src/client/play.js:20:24)
    at Client.<anonymous> (/home/gyanbu/cave_bot/node_modules/mineflayer/lib/plugins/chat.js:132:47)
    at Client.emit (node:events:513:28)
    at FullPacketParser.<anonymous> (/home/gyanbu/cave_bot/node_modules/minecraft-protocol/src/client.js:91:12)
    at FullPacketParser.emit (node:events:513:28)
    at addChunk (/home/gyanbu/cave_bot/node_modules/protodef/node_modules/readable-stream/lib/_stream_readable.js:298:12) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Node.js v18.12.1
AnyBananaGAME commented 2 years ago
bot.on('kicked', console.log("Kicked"))
bot.on('error', console.log("Error"))

ur console.log was wrong-

Gyanbu commented 2 years ago

That part wasn't even ran, I copied it from example. I checked and it works for version 1.12.2 Is there some newer method to read chat from 1.19.2?

AnyBananaGAME commented 2 years ago

1.19.2 is not supported im pretty sure-

Gyanbu commented 2 years ago

Features Supports Minecraft 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18 and 1.19.

amoraschi commented 2 years ago

Open a PR and edit the README.md if you want

Gyanbu commented 2 years ago

So it was added and no one checked? awensome!