PrismarineJS / mineflayer

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

[Python] Join and instally disconnects #3004

Open Turlt31 opened 1 year ago

Turlt31 commented 1 year ago

Versions

Detailed description of a problem

I copied the python bot code changed the host and port obv and when it joins the server it disconnected instantly

What did you try yet?

This happens with the python and javascript code

And i get this error:

Error: read ECONNRESET
    at TCP.onStreamRead (node:internal/stream_base_commons:217:20) {
  errno: -4077,
  code: 'ECONNRESET',
  syscall: 'read'
}

My code:

from javascript import require, On
mineflayer = require('mineflayer')
pathfinder = require('mineflayer-pathfinder')

RANGE_GOAL = 1
BOT_USERNAME = 'AfkBot'

bot = mineflayer.createBot({
  'host': xxxxxxxxxxxxx',
  'port': xxxxx,
  'username': BOT_USERNAME
})

bot.loadPlugin(pathfinder.pathfinder)
print("Started mineflayer")

@On(bot, 'spawn')
def handle(*args):
  print("I spawned 👋")
  movements = pathfinder.Movements(bot)

  @On(bot, 'chat')
  def handleMsg(this, sender, message, *args):
    print("Got message", sender, message)
    if sender and (sender != BOT_USERNAME):
      bot.chat('Hi, you said ' + message)
      if 'come' in message:
        player = bot.players[sender]
        print("Target", player)
        target = player.entity
        if not target:
          bot.chat("I don't see you !")
          return

        pos = target.position
        bot.pathfinder.setMovements(movements)
        bot.pathfinder.setGoal(pathfinder.goals.GoalNear(pos.x, pos.y, pos.z, RANGE_GOAL))

@On(bot, "end")
def handle(*args):
  #print("Bot ended!", args)
  pass
SonicandTailsCD commented 1 year ago

Hi! I see you're having a TCP error. This is normal, it doesn't have to do with Mineflayer. How about we try on my server? Maybe it has to do with your server, as TCP errors indicate your system didn't send anything on time to the server and got caught in an exception. :)

Turlt31 commented 1 year ago

How can i fix it?

SonicandTailsCD commented 1 year ago

How can i fix it?

There's no real way to fix a TCP error. One thing you could do is restart your server, router and PC that runs the bot. Another thing is to add a reconnect script to the bot.. I don't guarantee anything will work though. However, if you'd like, you could try to connect to my server, that will tell me if it's your network or your server. Want to do that? I'll only give my server IP and port if you say yes.

SonicandTailsCD commented 1 year ago

Hi! I noticed you've been offline/not answering for 2 weeks. If this issue has been fixed or is no longer relevant, please close this issue. Have fun coding!

TheMcSebi commented 11 months ago

I stumbled upon this while trying to get the same example to work. I didn't see any error message, but for some reason the node subprocesses on my machine appear to be demonized, since the python interpreter just quits after setting up all event handlers. I might have overlooked something in the docs, but for future readers: My solution was to just put a while True: time.sleep(1) at the end of the file to keep the bot running for more than three seconds.