PrismarineJS / mineflayer

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

Bot click on NPC? #826

Closed peter81745 closed 4 years ago

peter81745 commented 5 years ago

So i have written a bot that connects to a server, on the server there are npc's, to get to the Server. I Already managed to get the bot to the right npc but the problem is how can i make the bot do a rightclick on the npc?

wvffle commented 5 years ago

You can try bot.activateEntity(npcEntity)

peter81745 commented 5 years ago

yeah but how do i get the npcEntity? I searched for a nearestEntity function and found this:

function nearestEntity(type) {
  var id, entity, dist;
  var best = null;
  var bestDistance = null;
  for(id in bot.entities) {
    entity = bot.entities[id];
    if(type && entity.type !== type) continue;
    if(entity === bot.entity) continue;
    dist = bot.entity.position.distanceTo(entity.position);
    if(!best || dist < bestDistance) {
      best = entity;
      bestDistance = dist;
    }
  }
  return best;
}

bot.on('login', function() {
  sleep(10000).then(() => {
    var entity=nearestEntity(bot.entities)
    bot.activateEntity(entity)
  })

but it doesnt work. i get the error.

(node:11532) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'position' of null
    at Bot.activateEntity (E:\peter\NodeJS\Bausucht.net Bot\node_modules\mineflayer\lib\plugins\inventory.js:212:23)
    at sleep.then (E:\peter\NodeJS\Bausucht.net Bot\index.js:61:9)
(node:11532) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:11532) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
peter81745 commented 5 years ago

ok i solved the error but the bot still doesn't click on the npc

wvffle commented 5 years ago

Share the full code with us

peter81745 commented 5 years ago
var args = process.argv.slice(2);
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}
var mineflayer = require('mineflayer');
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var fs = require('fs');
const vec3 = require('vec3')
var readline = require('readline-sync');

console.log('Verbinde zu Server...');
var bot = mineflayer.createBot({
  host: "bausucht.net", // optional
  port: 25565,       // optional
  //username: "cfss",
  username: "email", // email and password are required only for
  password: "passwd",
  version: 1.8
});
console.log('Verbunden!');
/*
*/
navigatePlugin(bot);
bot.navigate.on('pathFound', function (path) {
});
bot.navigate.on('cannotFind', function (closestPath) {
  bot.navigate.walk(closestPath);
});
bot.navigate.on('arrived', function () {
});
bot.navigate.on('interrupted', function() {
});

function nearestEntity(type) {
  var id, entity, dist;
  var best = null;
  var bestDistance = null;
  for(id in bot.entities) {
    entity = bot.entities[id];
    if(type && entity.type !== type) continue;
    if(entity === bot.entity) continue;
    dist = bot.entity.position.distanceTo(entity.position);
    if(!best || dist < bestDistance) {
      best = entity;
      bestDistance = dist;
    }
  }
  return best;
}
/*
bot.navigate.to(bot.entity.position.offset(-1, 0, 0))
sleep(4000).then(() => {
  bot.chat("/p h CuzImPeter 4")
})

*/

bot.on('login', function() {
  sleep(2000).then(() => {
    var entity=nearestEntity();
    console.log(entity);
    bot.activateEntity(entity);
    //console.log(casl);
  })
peter81745 commented 5 years ago

can somebody help me now?

rom1504 commented 5 years ago

What's the error ?

plexigras commented 5 years ago

the trader example might be worth a look at

https://github.com/PrismarineJS/mineflayer/blob/master/examples/trader.js#L53-L58

peter81745 commented 5 years ago

@plexigras doesnt work getting error

(node:7312) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
+ expected - actual

- undefined
+ 120
    at Bot.openVillager (E:\peter\NodeJS\Bausucht.net Bot\node_modules\mineflayer\lib\plugins\villager.js:55:12)
    at sleep.then (E:\peter\NodeJS\Bausucht.net Bot\index.js:65:28)
(node:7312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:7312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
rom1504 commented 5 years ago

What did you run to get this

On Wed, Aug 7, 2019, 00:02 peter12908 notifications@github.com wrote:

@plexigras https://github.com/plexigras doesnt work getting error

(node:7312) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:

  • expected - actual

  • undefined

  • 120 at Bot.openVillager (E:\peter\NodeJS\Bausucht.net Bot\node_modules\mineflayer\lib\plugins\villager.js:55:12) at sleep.then (E:\peter\NodeJS\Bausucht.net Bot\index.js:65:28) (node:7312) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:7312) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/826?email_source=notifications&email_token=AAR437WMXNOMPZKAYZYU64LQDHYH3A5CNFSM4HW6SJF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3WTBGQ#issuecomment-518860954, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437XQ346ILR4EVEOKRMTQDHYH3ANCNFSM4HW6SJFQ .

peter81745 commented 5 years ago

my current code looks like this but now i wont get an error but also the bot doesn't gets send to the server

Code:

var args = process.argv.slice(2);
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}
var mineflayer = require('mineflayer');
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var fs = require('fs');
const vec3 = require('vec3')
var readline = require('readline-sync');

console.log('Verbinde zu Server...');
var bot = mineflayer.createBot({
  host: "bausucht.net", // optional
  port: 25565,       // optional
  username: "censored", // email and password are required only for
  password: "censored",
  version: 1.8
});
console.log('Verbunden!');
/*
*/
navigatePlugin(bot);
bot.navigate.on('pathFound', function (path) {
});
bot.navigate.on('cannotFind', function (closestPath) {
  bot.navigate.walk(closestPath);
});
bot.navigate.on('arrived', function () {
});
bot.navigate.on('interrupted', function() {
});

function nearestEntity(type) {
  var id, entity, dist;
  var best = null;
  var bestDistance = null;
  for(id in bot.entities) {
    entity = bot.entities[id];
    if(type && entity.type !== type) continue;
    if(entity === bot.entity) continue;
    dist = bot.entity.position.distanceTo(entity.position);
    if(!best || dist < bestDistance) {
      best = entity;
      bestDistance = dist;
    }
  }
  return best;
}

bot.on('login', function() {
  sleep(2000).then(() => {
    var entity=nearestEntity();
    console.log(entity);
    const pt = vec3(160, 98, 206)
    bot.navigate.to(pt)
    sleep(1200).then(() => {
      const pt2 = vec3(160, 98, 205)
      bot.navigate.to(pt2)
    sleep(2200).then(() => {
      bot.useOn(entity);
    })
  })
  })
})
bot.on('chat', function(username, message) {
    //bot.navigate.to(11, 65, 38)
    if (username === "CuzImPeter") {
    const target = bot.players[username].entity;
    if (message === 'komm') {
      try {
        bot.navigate.to(target.position);
      } catch {
        console.log('Ich kann dich nicht finden oder es gab einen Fehler.')
      }
    } else if (message === 'stop') {
      bot.navigate.stop();
  }
  if (message === 'hunger') {
    bot.chat("/tell CuzImPeter " + bot.food)
  }
  if (message === 'iss') {
    try {
      bot.equip(360, 'hand', (err) => {
      if (err) {
        return console.log(err.message)
      }

      bot.consume((err) => {
        if (err) {
          return console.log(err.message)
        }
      })
    })
  } catch {
      bot.chat("/tell CuzImPeter Kann nichts essen")
  }
  }
  if (message === 'botinfo') {
    console.log(bot.player)
  }
  if (message === 'ph') {
    bot.chat("/p h CuzImPeter 4")
  }
}
console.log(message, username)
});
rom1504 commented 5 years ago

We need one version of the code with the corresponding error.

On Wed, Aug 7, 2019, 00:23 peter12908 notifications@github.com wrote:

my current code looks like this but now i wont get an error but also the bot doesn't gets send to the server

Code:

var args = process.argv.slice(2); const sleep = (milliseconds) => { return new Promise(resolve => setTimeout(resolve, milliseconds)) } var mineflayer = require('mineflayer'); var navigatePlugin = require('mineflayer-navigate')(mineflayer); var fs = require('fs'); const vec3 = require('vec3') var readline = require('readline-sync');

console.log('Verbinde zu Server...'); var bot = mineflayer.createBot({ host: "bausucht.net", // optional port: 25565, // optional username: "censored", // email and password are required only for password: "censored", version: 1.8 }); console.log('Verbunden!'); / / navigatePlugin(bot); bot.navigate.on('pathFound', function (path) { }); bot.navigate.on('cannotFind', function (closestPath) { bot.navigate.walk(closestPath); }); bot.navigate.on('arrived', function () { }); bot.navigate.on('interrupted', function() { });

function nearestEntity(type) { var id, entity, dist; var best = null; var bestDistance = null; for(id in bot.entities) { entity = bot.entities[id]; if(type && entity.type !== type) continue; if(entity === bot.entity) continue; dist = bot.entity.position.distanceTo(entity.position); if(!best || dist < bestDistance) { best = entity; bestDistance = dist; } } return best; }

bot.on('login', function() { sleep(2000).then(() => { var entity=nearestEntity(); console.log(entity); const pt = vec3(160, 98, 206) bot.navigate.to(pt) sleep(1200).then(() => { const pt2 = vec3(160, 98, 205) bot.navigate.to(pt2) sleep(2200).then(() => { bot.useOn(entity); }) }) }) }) bot.on('chat', function(username, message) { //bot.navigate.to(11, 65, 38) if (username === "CuzImPeter") { const target = bot.players[username].entity; if (message === 'komm') { try { bot.navigate.to(target.position); } catch { console.log('Ich kann dich nicht finden oder es gab einen Fehler.') } } else if (message === 'stop') { bot.navigate.stop(); } if (message === 'hunger') { bot.chat("/tell CuzImPeter " + bot.food) } if (message === 'iss') { try { bot.equip(360, 'hand', (err) => { if (err) { return console.log(err.message) }

  bot.consume((err) => {
    if (err) {
      return console.log(err.message)
    }
  })
})

} catch { bot.chat("/tell CuzImPeter Kann nichts essen") } } if (message === 'botinfo') { console.log(bot.player) } if (message === 'ph') { bot.chat("/p h CuzImPeter 4") } } console.log(message, username) });

— You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub https://github.com/PrismarineJS/mineflayer/issues/826?email_source=notifications&email_token=AAR437VX4UZ2XORWODVPSQTQDH2WLA5CNFSM4HW6SJF2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD3WUJWA#issuecomment-518866136, or mute the thread https://github.com/notifications/unsubscribe-auth/AAR437SA7EGOUBOEMFQBUATQDH2WLANCNFSM4HW6SJFQ .

peter81745 commented 5 years ago

Code:

var args = process.argv.slice(2);
const sleep = (milliseconds) => {
  return new Promise(resolve => setTimeout(resolve, milliseconds))
}
var mineflayer = require('mineflayer');
var navigatePlugin = require('mineflayer-navigate')(mineflayer);
var fs = require('fs');
const vec3 = require('vec3')
var readline = require('readline-sync');

console.log('Verbinde zu Server...');
var bot = mineflayer.createBot({
  host: "bausucht.net", // optional
  port: 25565,       // optional
  //username: "cfss",
  username: "censored", // email and password are required only for
  password: "censored",
  version: 1.8
});
console.log('Erfolgreich in Account eingeloggt!');
/*
*/
navigatePlugin(bot);
bot.navigate.on('pathFound', function (path) {
});
bot.navigate.on('cannotFind', function (closestPath) {
  bot.navigate.walk(closestPath);
});
bot.navigate.on('arrived', function () {
});
bot.navigate.on('interrupted', function() {
});

function nearestEntity(type) {
  var id, entity, dist;
  var best = null;
  var bestDistance = null;
  for(id in bot.entities) {
    entity = bot.entities[id];
    if(type && entity.type !== type) continue;
    if(entity === bot.entity) continue;
    dist = bot.entity.position.distanceTo(entity.position);
    if(!best || dist < bestDistance) {
      best = entity;
      bestDistance = dist;
    }
  }
  return best;
}

bot.on('login', function() {
  console.log("Verbunden mit Server!");
  sleep(2000).then(() => {
    var entity=nearestEntity();
    //const entity = Object.keys(bot.entities).map(id => bot.entities[id]).filter(e => e.entityType === 78)
    console.log(entity);
    console.log(entity["id"]);
    //console.log(entity[1]);
    //console.log(entity["id"]);
    const pt = vec3(160, 98, 206)
    bot.navigate.to(pt)
    sleep(1200).then(() => {
      bot.setQuickBarSlot(3)
      const pt2 = vec3(160, 98, 205)
      bot.navigate.to(pt2)
    sleep(2200).then(() => {
      bot.openVillager(entity);
    })
  })
  })
})
bot.on('chat', function(username, message) {
    //bot.navigate.to(11, 65, 38)
    if (username === "CuzImPeter") {
    const target = bot.players[username].entity;
    if (message === 'komm') {
      try {
        bot.navigate.to(target.position);
      } catch {
        console.log('Ich kann dich nicht finden oder es gab einen Fehler.')
      }
    } else if (message === 'stop') {
      bot.navigate.stop();
  }
  if (message === 'hunger') {
    bot.chat("/tell CuzImPeter " + bot.food)
  }
  if (message === 'iss') {
    try {
      bot.equip(360, 'hand', (err) => {
      if (err) {
        return console.log(err.message)
      }

      bot.consume((err) => {
        if (err) {
          return console.log(err.message)
        }
      })
    })
  } catch {
      bot.chat("/tell CuzImPeter Kann nichts essen")
  }
  }
  if (message === 'botinfo') {
    console.log(bot.player)
  }
  if (message === 'ph') {
    bot.chat("/p h CuzImPeter 4")
  }
}
console.log(message, username)
});

Error:

(node:14700) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Input A expected to strictly equal input B:
+ expected - actual

- 78
+ 120
    at Bot.openVillager (E:\peter\NodeJS\Bausucht.net Bot\node_modules\mineflayer\lib\plugins\villager.js:55:12)
    at sleep.then (E:\peter\NodeJS\Bausucht.net Bot\index.js:67:11)
(node:14700) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:14700) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
rom1504 commented 5 years ago

ok so the issue is you're trying to use openVillager on an entity which is not a villager. why is that ?

peter81745 commented 5 years ago

I am trying to click on an NPC that looks like a normal player, when you rightclick on it you get teleported to another server. I also tried bot.mount or bot.useOn but the bot doesn't get send to the Server... and nothing happens

wvffle commented 5 years ago

Have you tried to activateEntity in front of the NPC?

peter81745 commented 5 years ago

yes also didn't work...

cyborgcodede commented 4 years ago

Hi, did you find a way to click the NPC?

wvffle commented 4 years ago

@CyborgCodeDEV and @peter12908, you can use mcpd to check what packets does the client send to the NPC, then just give us the screenshot ;)

cyborgcodede commented 4 years ago

@wvffle ok I started mcpd and entered the IP in the settings but there are no packages listed. I also tried it with a localhost server but it didn't work either.

wvffle commented 4 years ago

You have to connect to the proxy server, which by default runs on the localhost:25566 and then record the packets

cyborgcodede commented 4 years ago

I connected through the proxy but now I get 'undefined' in MC. When I connect to my localhost I get this error in the console:

[11:20:47] [User Authenticator #1/ERROR]: Username 'zvq' tried to join with an invalid session
[11:20:47] [Server thread/INFO]: /127.0.0.1:54540 lost connection: Failed to verify username!
cyborgcodede commented 4 years ago

I set my localhost server to online-mode=false and now it works. When I click a npc on my localhost (Citizens NPC) it sends the use_entity packet twice:

first one looks like this:

Packet:

{
  "target": 3597,
  "mouse": 2,
  "x": -0.2303556501865387,
  "y": 1.304377555847168,
  "z": -0.4000000059604645
}

Meta:

{
  "size": 16,
  "name": "use_entity",
  "state": "play"
}

and second one looks like this:

Packet:

{
  "target": 3597,
  "mouse": 0,
  "x": null,
  "y": null,
  "z": null
}

Meta:

{
  "size": 4,
  "name": "use_entity",
  "state": "play"
}

But when I add a command to the NPC it gets executed perfectly fine on bot.useOn(entity) When I use exactly the same code on the server I want it to click the NPC, nothing happens

This is the entity data of the NPC I want to click:

Entity {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: 15,
  type: 'player',
  position: Vec3 { x: 160.46875, y: 99, z: 203.40625 },
  velocity: Vec3 { x: 0, y: 0, z: 0 },
  yaw: 5.522330836388308,
  pitch: 0.024543692606170175,
  onGround: true,
  height: 1.62,
  effects: {},
  equipment: [ <5 empty items> ],
  heldItem: undefined,
  isValid: true,
  metadata: {
    '0': 0,
    '1': 300,
    '2': '',
    '3': 0,
    '4': 0,
    '6': 20,
    '7': 0,
    '8': 0,
    '9': 0,
    '10': 0,
    '16': 0,
    '17': 0,
    '18': 0
  },
  username: '§e',
  uuid: 'b8d5c7ad-74bc-514e-0000-000000000000',
  dataBlobs: undefined,
  headYaw: 5.522330836388308,
  [Symbol(kCapture)]: false
}

This is the entity data of the NPC I can click perfectly:

Entity {
  _events: [Object: null prototype] {},
  _eventsCount: 0,
  _maxListeners: undefined,
  id: 242,
  type: 'player',
  position: Vec3 { x: 240.78125, y: 72, z: 244.46875 },
  velocity: Vec3 { x: 0, y: 0, z: 0 },
  yaw: 0.19634954084936185,
  pitch: 0,
  onGround: true,
  height: 1.62,
  effects: {},
  equipment: [ null, null, null, null, <1 empty item> ],
  heldItem: null,
  isValid: true,
  metadata: {
    '0': 0,
    '1': 300,
    '2': 'StupidNPC',
    '3': 1,
    '4': 0,
    '6': 20,
    '7': 0,
    '8': 0,
    '9': 0,
    '10': -1,
    '16': 0,
    '17': 0,
    '18': 0
  },
  username: 'StupidNPC',
  uuid: 'be0b3a3e-1e9a-28ec-9bac-ed644b6f545a',
  dataBlobs: undefined,
  headYaw: 0.19634954084936185,
  [Symbol(kCapture)]: false
}

Thanks for your help!

Systemwartung commented 4 years ago

Have IT works if yes can you Sand me the Code because I search for a log time and I didnt find a answer

In German

Kannst du wenn es geklappt hat mit bitte den Code schicken ich verzweifele dran und bekomme es nicht hin auf Bausucht.net auf den npc zu drücken

rom1504 commented 4 years ago

Seems it's solved

adriabama06 commented 4 years ago

I am Spanish ok ... but I am not clear what I have to do in order to make it work (I am noob), I share my code so you know what I have and if it can interfere:

var mineflayer = require('mineflayer')
const pathfinder = require('mineflayer-pathfinder').pathfinder
const Movements = require('mineflayer-pathfinder').Movements
const { GoalNear } = require('mineflayer-pathfinder').goals
const navigatePlugin = require('mineflayer-navigate')(mineflayer);
const { performance } = require('perf_hooks')
var blockFinderPlugin = require('mineflayer-blockfinder')(mineflayer);
const vec3 = require('vec3')
var bot = mineflayer.createBot({
  host: "opnetwork.ddns.net", // ip del server
  port: 25565,       // por defecto 25565
  username: "namexd", // email and password are required only for
//  password: "no premium network",          // online-mode=true servers
  version: 1.8               // false corresponds to auto version detection (that's the default), put for example "1.8.8" if you need a specific version
});

require('mineflayer-armor-manager')(bot);

var prefix = "!";

function sleep(time, callback) {
  var stop = new Date().getTime();
  while(new Date().getTime() < stop + time) {
      ;
  }
  callback();
}

//login del servidor

bot.on('login', function() {

    console.log("Bot conectado, logeanodo automaticamente...")
  sleep(3000, function() {
    // executes after one second, and blocks the thread
 });
    bot.chat("/login my secret pass")
    sleep(100, function() {
      // executes after one second, and blocks the thread
});
});

//captcha

//captcha current off xd

bot.on('chat', (message) => {
//  if (username === bot.username) return;
  console.log(message);
});

//bot.on('error', err => console.log(err);

//chat

bot.on('chat', (message) => {

  if (message.includes('hola')) {
    sleep(1000, function() {
      // executes after one second, and blocks the thread
    });
    bot.chat("hola")
  }

});

bot.on('chat', (message) => {

  if (message.includes('XD')) {
    sleep(1000, function() {
      // executes after one second, and blocks the thread
   });
    bot.chat("XD")
  }

});

bot.on('chat', (message) => {

  if (message.includes('...')) {
    sleep(1000, function() {
      // executes after one second, and blocks the thread
    });
    bot.chat("...")
  }

});

bot.on('chat', (message) => {

  if (message.startsWith('tpa')) {
    bot.chat("/tpa adriabama06")
  }

});

//commandos

bot.on('chat', (message) => {

  if (message.startsWith('jobs')) {
    bot.chat("/jobs join miner")
  }

});

//movimieto come

navigatePlugin(bot);
// optional configuration
bot.navigate.blocksToAvoid[132] = true; // avoid tripwire
bot.navigate.blocksToAvoid[59] = false; // ok to trample crops
bot.navigate.on('pathFound', function (path) {
  console.log("He encontrado un camino, llegare en " + path.length + " movimientos");
});
bot.navigate.on('cannotFind', function (closestPath) {
  console.log("No encontre la ruta perfecta me acercare lo maximo posible");
  bot.navigate.walk(closestPath);
});
bot.navigate.on('arrived', function () {
  console.log("He llegado");
});
bot.navigate.on('interrupted', function() {
  console.log("Parando");
});
bot.on('chat', function(username, message) {
  // navigate to whoever talks
  if (username === bot.username) return;
//  const target = bot.players[username].entity.position; <-- dosen't work
  if (message === prefix +'come') {
    bot.navigate.to(target/*.position*/);
  } else if (message === prefix +'stop') {
    bot.navigate.stop();
  }
});

//by can build bcome

bot.loadPlugin(pathfinder)

bot.on('chat', function(username, message) {
    const mcData = require('minecraft-data')(bot.version)

    const defaultMove = new Movements(bot, mcData)
    // navigate to whoever talks
    if (username === bot.username) return;
//    const target = bot.players[username].entity.position; <-- dosen't work
    if (message === prefix +'bcome') {
        const p = target//.position
        bot.pathfinder.setMovements(defaultMove)
        bot.pathfinder.setGoal(new GoalNear(p.x, p.y, p.z, 1))
    }
});

//gotop

bot.on('chat', function(username, message) {
  const mcData = require('minecraft-data')(bot.version)

  const defaultMove = new Movements(bot, mcData)
  // navigate to whoever talks
  if (username === bot.username) return;
  if (message.startsWith(prefix +'gotop')) {
    const name = message.split(' ')[1]
    const target = bot.players[name].entity;
      const p = target.position
      bot.pathfinder.setMovements(defaultMove)
      bot.pathfinder.setGoal(new GoalNear(p.x, p.y, p.z, 1))
  }
});

//ves a un sitio exacto

bot.on('chat', function(username, message) {
  const mcData = require('minecraft-data')(bot.version)

  const defaultMove = new Movements(bot, mcData)
  // navigate to whoever talks
  if (username === bot.username) return;
  if (message.startsWith(prefix +'goto')) {
    const x = message.split(' ')[1]
    const y = message.split(' ')[2]
    const z = message.split(' ')[3]
      bot.pathfinder.setMovements(defaultMove)
      bot.pathfinder.setGoal(new GoalNear(x, y, z, 1))
  }
});

//block finder

// Install the plugin
bot.loadPlugin(blockFinderPlugin);

// Sample usage
bot.on('chat', function(username, message) {
  if (message.startsWith(prefix +'find')) {
  bot.findBlock({
    point: bot.entity.position,
    matching: 56,
    maxDistance: 256,
    count: 1,
  }, function(err, blocks) {
    if (err) {
      return console.log('Hubo un error: ' + err);
      bot.chat("/msg " + username + " Hubo un error: " + err + ".")
      return;
    }
    if (blocks.length) {
      console.log('He encontrado en ' + blocks[0].position + '.');
      bot.chat("/msg " + username + " He encontrado en " + blocks[0].position + ".")

      return;
    } else {
      console.log("No pude encontrar el bloque a menos de 256.");
      bot.chat("/msg " + username + " No pude encontrar el bloque a menos de 256.")

      return;
    }
  })
  };
});

//find and got

bot.on('chat', function(username, message) {
  const mcData = require('minecraft-data')(bot.version)

  const defaultMove = new Movements(bot, mcData)
  if (message.startsWith(prefix +'findg')) {
  bot.findBlock({
    point: bot.entity.position,
    matching: 56,
    maxDistance: 256,
    count: 1,
  }, function(err, blocks) {
    if (err) {
      return console.log('Hubo un error: ' + err);
      bot.chat("/msg " + username + " Hubo un error: " + err + ".")
      return;
    }
    if (blocks.length) {
      console.log('He encontrado en ' + blocks[0].position + '.');
      bot.chat("/msg " + username + " He encontrado en " + blocks[0].position + ".")
      const x = blocks[0].position.x
      const y = blocks[0].position.y
      const z = blocks[0].position.z
        bot.pathfinder.setMovements(defaultMove)
        bot.pathfinder.setGoal(new GoalNear(x, y, z, 1))
    }
  })
  };
});

//cofres e items

bot.on('kicked', function(reason) {
    console.log('Has sido kickeado o baneado por',reason);
});

//salir del bot
bot.on('chat', function(username, message) {

  if (message.startsWith('exit')) {
    bot.quit('Sliendo');
  }

});

and the error:

C:\Users\adria\Pictures\opbot\bot.js:127
  const target = bot.players[username].entity.position;// <-- dosen't work
                                       ^

TypeError: Cannot read property 'entity' of undefined
    at Bot.<anonymous> (C:\Users\adria\Pictures\opbot\bot.js:127:40)
    at Bot.emit (events.js:327:22)
    at checkForChatPatterns (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\lib\plugins\chat.js:54:60)
    at Client.<anonymous> (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\lib\plugins\chat.js:70:5)
    at Client.emit (events.js:315:20)
    at FullPacketParser.<anonymous> (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\node_modules\minecraft-protocol\src\client.js:87:12)
    at FullPacketParser.emit (events.js:315:20)
    at addChunk (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:298:12)
    at readableAddChunk (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:280:11)
    at FullPacketParser.Readable.push (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:241:10)
    at FullPacketParser.Transform.push (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:139:32)
    at FullPacketParser._transform (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\node_modules\protodef\src\serializer.js:81:10)
    at FullPacketParser.Transform._read (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:177:10)
    at FullPacketParser.Transform._write (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:164:83)
    at doWrite (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:409:139)
    at writeOrBuffer (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:398:5)
    at FullPacketParser.Writable.write (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:307:11)
    at Decompressor.ondata (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:681:20)
    at Decompressor.emit (events.js:315:20)
    at addChunk (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:298:12)
    at readableAddChunk (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:280:11)
    at Decompressor.Readable.push (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_readable.js:241:10)
    at Decompressor.Transform.push (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:139:32)
    at Decompressor._transform (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\node_modules\minecraft-protocol\src\transforms\compression.js:52:12)
    at Decompressor.Transform._read (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:177:10)
    at Decompressor.Transform._write (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:164:83)
    at doWrite (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:409:139)
    at clearBuffer (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:526:7)
    at onwrite (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:455:7)
    at WritableState.onwrite (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_writable.js:160:5)
    at Decompressor.afterTransform (C:\Users\adria\Pictures\opbot\node_modules\readable-stream\lib\_stream_transform.js:89:3)
    at Unzip.cb (C:\Users\adria\Pictures\opbot\node_modules\mineflayer\node_modules\minecraft-protocol\src\transforms\compression.js:70:16)
    at Unzip.zlibBufferOnEnd (zlib.js:149:10)
    at Unzip.emit (events.js:327:22)
    at endReadableNT (_stream_readable.js:1221:12)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
rom1504 commented 4 years ago

please create your own issue