Death causes crash. Bot is undefined
- [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
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
Confirmed, 1.21.4
Have you found a solution? I'm struggling with this problem too.
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.
The most simple bot code, will make this happen.
Creates the bot, makes it join a server, then kills it. Voilà ✨
Confirmed, 1.21.6 (same code as Emibergo02)
I think it only occurs when using bun instead of nodejs
@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.