PrismarineJS / mineflayer

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

1.19.3 - Chat session not initialized. Can't send chat #2965

Closed AnthonyvW closed 1 year ago

AnthonyvW commented 1 year ago

Versions

Detailed description of a problem

When the bot tries to say anything on an authenticated java edition server (no plugins) using bot.chat("message") it throws this error

C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\minecraft-protocol\src\client\chat.js:374
      if (!client._session.uuid) throw Error("Chat session not initialized. Can't send chat")
                           ^

TypeError: Cannot read properties of undefined (reading 'uuid')
    at client.signMessage (C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\minecraft-protocol\src\client\chat.js:374:28)
    at client._signedChat (C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\minecraft-protocol\src\client\chat.js:329:48)
    at C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\mineflayer\lib\plugins\chat.js:177:21
    at Array.forEach (<anonymous>)
    at chatWithHeader (C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\mineflayer\lib\plugins\chat.js:171:25)
    at bot.chat (C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\mineflayer\lib\plugins\chat.js:207:5)
    at EventEmitter.<anonymous> (C:\Users\Me\Desktop\MineFlayer\Bot\index.js:19:7)
    at EventEmitter.emit (node:events:513:28)
    at EventEmitter.<anonymous> (C:\Users\Me\Desktop\MineFlayer\Bot\node_modules\mineflayer\lib\plugins\chat.js:85:13)
    at EventEmitter.emit (node:events:513:28)

What did you try yet?

I tried uninstall mineflayer, mineflayer pathfinder, updating npm, updating node.js, deleting everything but the script that contains the bot and then reinstalling everything.

Did you try any example? Any error from those? I tried the mineflayer example, but changed a few lines so it uses microsoft authentication and takes in commandline arguments for the username/ip/port/password

Your current code


const mineflayer = require('mineflayer')

if (process.argv.length < 4 || process.argv.length > 6) {
  console.log('Usage : node farmer.js <host> <port> [<name>] [<password>]')
  process.exit(1)
}

const bot = mineflayer.createBot({
  host: process.argv[2],
  port: parseInt(process.argv[3]),
  username: process.argv[4],
  //password: process.argv[5],
  auth: 'microsoft'
})

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

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

Expected behavior

after the bot logs into the server and you say something in chat it repeats what you said.

Additional context

I tried asking about how to fix this in the mineflayer discord server and no one was able to figure it out.

stefexec commented 1 year ago

I am experiencing the same issue on a fresh install as well. No solution so far, will update if I find something.

edit: try

disableChatSigning: true

frej4189 commented 1 year ago

This will be fixed with next release for NMP.

ghost commented 1 year ago

mit

I'm still struggling with this issue on the latest version whilst connected to online servers, any advice?

extremeheat commented 1 year ago

@FelixCharm

I'm still struggling with this issue on the latest version whilst connected to online servers, any advice?

It's not released, you can open a release PR in node-minecraft-protocol

ghost commented 1 year ago

@FelixCharm

I'm still struggling with this issue on the latest version whilst connected to online servers, any advice?

It's not released, you can open a release PR in node-minecraft-protocol

oh ok, thanks