Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR bot.fish() ! #3456

Open
ibrahim12651 opened this issue Sep 11, 2024 · 4 comments
Open

ERROR bot.fish() ! #3456

ibrahim12651 opened this issue Sep 11, 2024 · 4 comments
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f

Comments

@ibrahim12651
Copy link

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)

@ibrahim12651 ibrahim12651 added possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f labels Sep 11, 2024
@BF5258
Copy link

BF5258 commented Sep 26, 2024

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
Copy link
Author

ibrahim12651 commented Sep 26, 2024

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
Copy link

BF5258 commented Sep 26, 2024

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

@ibrahim12651
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
possible bug Stage1 just created by someone new to the project, we don't know yet if it deserves an implementation / a f
Projects
None yet
Development

No branches or pull requests

2 participants