mineflayer
mineflayer copied to clipboard
How to respawn bot?
Sometimes, when my bot is killed, it can't respawn and sends to the logs "Cannot send chat message". Maybe there is a way to respawn it?
The bot should auto respawn, if it's not doing that, maybe there's something blocking the process and slowing down the bot, what's your code?
await bot.once('spawn', ()=> {
bot.chat("/login "+pass);
setTimeout(() => {
bot.chat('/servers');
}, 400);
});
var slot = 12;
await bot.on('windowOpen', (window) => {
bot.clickWindow(slot, 1, 0);
bot.closeWindow(window)
});
bot.on('death', ()=> {
setTimeout(() => {
bot.chat('/warp testwarp')
}, 300);
})
bot.on('messagestr', (message, messagePosition, jsonMsg)=> {
if (message.includes("Welcome!")){
setTimeout(() => {
setTimeout(() => {
bot.chat('/warp testwarp')
}, 150);
}, 400);
}
}
})
bot.on('error', (err)=> {
bot.quit()
})
}
And it can't respawn after rejoin
the thing ur doing wrong is bot.on('death', ()=> { setTimeout(() => { bot.chat('/warp testwarp') }, 300); })
bot.on('death') should respawn the bot but it types the chat in the respawn screen causing the bot to stay stuck on that screen try using bot.on('spawn', ()=> {bot.chat('/warp testwarp')})
and on the top u declared that on spawn the bot does the authentication which should be done on bot.on('login')
and a main thing dont use bot.once
whenever the bot spawns instead use bot.on('spawn')
its better u can use bot.once()
when u want to login
Try removing the /warp on respawn event and see if it works correctly