PrismarineJS / mineflayer

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

ERROR bot.fish() ! #3456

Closed ibrahim12651 closed 1 month ago

ibrahim12651 commented 2 months ago
let fishingInProgress = false; 
let fishingTimeout = null; 
let retryFishing = false;

bot.on('spawn', () => {
  console.log('Bot dünyaya girdi!');
  bot.chat('/register');
  bot.chat('/login ');

  setTimeout(() => {
    bot.chat('/skyblock');
    setTimeout(startFishing, 5000);
  }, 2000);
});

function startFishing() {
  if (fishingInProgress) {
    console.log('Balık tutma işlemi zaten devam ediyor.');
    return;
  }

  fishingInProgress = true;
  retryFishing = false;
  console.log('Olta atılıyor...');

  bot.fish().then(() => {
    console.log('Balık başarıyla yakalandı!');
    fishingInProgress = false;
    clearTimeout(fishingTimeout);
    sendInventoryToDiscord();
    setTimeout(startFishing, 5000);
  }).catch((err) => {
    console.error('Balık tutma sırasında hata oluştu:', err);
    fishingInProgress = false;
    clearTimeout(fishingTimeout);
    if (!retryFishing) {
      retryFishing = true;
      setTimeout(startFishing, 5000);
    }
  });

  fishingTimeout = setTimeout(() => {
    if (fishingInProgress) {
      console.log('Balık yakalanamadı, tekrar deneme yapılıyor.');
      bot.activateItem();
      fishingInProgress = false;
      if (!retryFishing) {
        retryFishing = true;
        setTimeout(startFishing, 5000); 
      }
    }
  }, 33000);
}

What's really the problem ?

\node_modules\mineflayer\lib\plugins\fishing.js:45 fishingTask.cancel(new Error('Fishing cancelled due to calling bot.fish() again')) ^

Error: Fishing cancelled due to calling bot.fish() again at EventEmitter.fish (C:\Users\Desktop\MFishBot\node_modules\mineflayer\lib\plugins\fishing.js:45:26) at Timeout.startFishing [as _onTimeout] (C:\Users\bekta\Desktop\MFishBot\index.js:55:7) at listOnTimeout (node:internal/timers:581:17) at process.processTimers (node:internal/timers:519:7)

BF5258 commented 2 months ago

This is not a bug in mineflayer. If you would like help writing code please go to the Mineflayer Forums.

Error: Fishing cancelled due to calling bot.fish() again As the error states your code has called bot.fish() again before the bot finished fishing the first time. Calling bot.activateItem() does real in the rod but does not cancel the previous bot.fish().

Corrected code

let fishingInProgress = false; 
let fishingTimeout = null; 
let retryFishing = false;

bot.on('spawn', () => {
  console.log('Bot dünyaya girdi!');
  bot.chat('/register');
  bot.chat('/login ');

  setTimeout(() => {
    bot.chat('/skyblock');
    setTimeout(startFishing, 5000);
  }, 2000);
});

function startFishing() {
  if (fishingInProgress) {
    console.log('Balık tutma işlemi zaten devam ediyor.');
    return;
  }

  fishingInProgress = true;
  retryFishing = false;
  console.log('Olta atılıyor...');

  bot.fish().then(() => {
    console.log('Balık başarıyla yakalandı!');
    fishingInProgress = false;
    clearTimeout(fishingTimeout);
    sendInventoryToDiscord();
    setTimeout(startFishing, 5000);
  }).catch((err) => {
    console.error('Balık tutma sırasında hata oluştu:', err);
    fishingInProgress = false;
    clearTimeout(fishingTimeout);
    if (!retryFishing) {
      retryFishing = true;
      setTimeout(startFishing, 5000);
    }
  });
ibrahim12651 commented 2 months ago

Hello yes the code is working properly thank you!

it worked 5-6 times and then stopped, why did such a thing happen, is it related to the server, I wonder?

BF5258 commented 2 months ago

Did it give an error message or just stop with its line out/in?

ibrahim12651 commented 1 month ago

Did it give an error message or just stop with its line out/in?

The system doesn't give an error, it holds 6 to 5 items and then releases them.