mineflayer
mineflayer copied to clipboard
bot.consume() keeps throwing "promise timeout" errors
- [x] The FAQ doesn't contain a resolution to my issue
Versions
- mineflayer: 4.2.0
- server: vanilla 1.18.2
- node: 17.5.0
Detailed description of a problem
I'm trying to prevent my bot from starving to death using super simple code.
What did you try yet?
I've tried using the auto-eat plugin, I've tried stepping in and out the errors. I just cant find the problem. I remember seeing similar issues online having to do with inventory.js but none have actual answers.
Your current code
bot.consume().then(() => {
console.log("Finished eating")
}).catch((err: any) => {
console.log(err)
})
Expected behavior
I expected the bot to eat and not have a heart attack and crash.
Additional context
There is always food in it's first slot. I'm also watching the bot's behavior in-game using LAN. It finishes eating properly, but it always throws a Promise timed out
error a second or two after.
Initially I was using the auto-eat plugin, which would give me the same error. I used this as a fallback thinking it was a problem with the plugin itself, only to be extremely confused.
The complete code block is as follows:
bot.on('health', () => {
console.log("Health: " + bot.health)
console.log("Food: " + bot.food)
if (bot.food < 18) {
if (edibleItems.length >= 1) {
// There is an issue with this functions internal promise not being resolved
// I think it has to do with the inventory not being updated, but I can't find the cause
bot.consume().then(() => {
console.log("Finished eating")
}).catch((err: any) => {
console.log(err)
})
}
}
})
Any help would be greatly appreciated.
Trying reformatting your code to not use callbacks. Use async/await instead.
Trying reformatting your code to not use callbacks. Use async/await instead.
Thanks for the reply. Even with async/await I'm getting the same error.