PrismarineJS / mineflayer

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

minecraft-protocol error #3451

Open lucia-developer opened 2 months ago

lucia-developer commented 2 months ago

Versions

Detailed description of a problem

A clear and concise description of what the problem is, with as much context as possible. What are you building? What problem are you trying to solve?

I'm trying to connect a bot to a server, make it run a command, and send a message to the chat (this is future, the current problem is connecting the bot). The problem is when I connect the bot I get a weird error:

What did you try yet?

Did you try any method from the API? Did you try any example? Any error from those?

I tried examples, none worked, same error.

Your current code


const mineflayer = require('mineflayer')
const { mineflayer: mineflayerViewer } = require('prismarine-viewer')
const bot = mineflayer.createBot({
  host: 'ip-redacted',
  username: 'username',
  auth: 'offline',
  port: 25565,
  version: "1.20.2",

})

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

bot.once('spawn', () => {
    mineflayerViewer(bot, { port: 3007, firstPerson: false })
  })
bot.on('kicked', console.log)
bot.on('error', console.log)

Expected behavior

A clear and concise description of what you expected to happen.

The bot joins the server and I get the view from prismarine-viewer.

Additional context

Add any other context about the problem here. The error is this one:

(bot connects)
ChatMessage {
  json: { text: '' },
  warn: [Function: debug] {
    namespace: 'minecraft-protocol',
    useColors: true,
    color: 3,
    extend: [Function: extend],
    destroy: [Function: deprecated],
    enabled: [Getter/Setter],
    inspectOpts: {}
  },
  text: '',
  bold: undefined,
  italic: undefined,
  underlined: undefined,
  strikethrough: undefined,
  obfuscated: undefined,
  color: undefined
}

(exits program/script)
mdmanl commented 1 month ago

Mineflayer doesn't support 1.21, expected behaviour.

spamshaker commented 2 weeks ago

any alternatives to just run the LAN game and start writing the code without such headaches?