mineflayer icon indicating copy to clipboard operation
mineflayer copied to clipboard

bot.consume() keeps throwing "promise timeout" errors

Open yurei-dll opened this issue 2 years ago • 2 comments

  • [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.

yurei-dll avatar Apr 11 '22 19:04 yurei-dll

Trying reformatting your code to not use callbacks. Use async/await instead.

U5B avatar Apr 13 '22 19:04 U5B

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.

yurei-dll avatar Apr 14 '22 05:04 yurei-dll