mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

Death causes crash. Bot is undefined

Open Emibergo02 opened this issue 11 months ago • 9 comments

  • [x] The FAQ doesn't contain a resolution to my issue

Versions

  • mineflayer: 4.25.0
  • server: paper 1.21.3
  • node: 21

Detailed description of a problem

204 | 
205 |     await diggingTask.promise
206 |   }
207 |
208 |   bot.on('death', () => {
209 |     bot.removeAllListeners('diggingAborted')
              ^
TypeError: undefined is not an object (evaluating 'this._events')
      at removeAllListeners (node:events:453:25)
      at <anonymous> (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\mineflayer\lib\plugins\digging.js:209:9)
      at emit (node:events:308:22)
      at <anonymous> (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\mineflayer\lib\plugins\health.js:25:13)
      at emit (node:events:314:22)
      at emitPacket (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\minecraft-protocol\src\client.js:84:12)
      at <anonymous> (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\minecraft-protocol\src\client.js:113:9)
      at emit (node:events:311:22)
      at addChunk (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\readable-stream\lib\internal\streams\readable.js:323:12)
      at readableAddChunk (C:\Users\Gigietto\WebstormProjects\Bot-test\node_modules\readable-stream\lib\internal\streams\readable.js:300:9)

What did you try yet?

To make the bots safe without dying. If they not die it works fine as always

Your current code

createBot({
    host: 'localhost', // Replace with your server's IP
    port: 25565,       // Replace with your server's port
    username: 'aaa0',
    version: '1.21.3'
})

Expected behavior

Normal handling with death event calling the listener

Emibergo02 avatar Jan 09 '25 17:01 Emibergo02

Simplified the code even more

createBot({
    host: 'localhost', // Replace with your server's IP
    port: 25565,       // Replace with your server's port
    username: 'aaa0',
    version: '1.21.3'
})

To reproduce: Just kill the player or make it die by a zombie

Emibergo02 avatar Jan 09 '25 17:01 Emibergo02

Confirmed, 1.21.4

fucksophie avatar Mar 06 '25 12:03 fucksophie

Have you found a solution? I'm struggling with this problem too.

evvskx avatar Apr 23 '25 10:04 evvskx

There's not enough information here on how to reproduce. If you have steps on how to reproduce from scratch from a vanilla server, then we can look into it. That error doesn't look right based on the code you provided.

extremeheat avatar Apr 24 '25 04:04 extremeheat

The most simple bot code, will make this happen.

fucksophie avatar May 04 '25 12:05 fucksophie

Creates the bot, makes it join a server, then kills it. Voilà ✨

iSnakeBuzz avatar Jun 20 '25 23:06 iSnakeBuzz

Confirmed, 1.21.6 (same code as Emibergo02)

fucksophie avatar Jun 21 '25 08:06 fucksophie

I think it only occurs when using bun instead of nodejs

XielQs avatar Jun 27 '25 13:06 XielQs

@extremeheat elaboration: the issue occurs when the bot is already dead and has not respawned when it connects. i am using bun which seems to support that it only happens on bun but i have not tried node. this is still an issue, because seemingly interacting with the bot's attached event listeners while the bot is dead causes issues, but it can be circumvented by simply disabling the digging plugin with mineflayer.createBot({ plugins: { digging: false } }). once the bot loads in it can respawn on its own if respawn is set to true or be manually respawned.

thonkinator avatar Jul 25 '25 02:07 thonkinator