I made a simple AFK bot for my Aternos server using mineflayer. It seemed to be working fine when run locally from my computer. But when I tried to deploy it using render it just kept leaving and joining. Here's my code:
const mineflayer = require('mineflayer')
const botargs = {
host: 'MY SMP ADDRESS',
port: 24383,
username: 'AFKBot',
};
function initBot() {
bot = mineflayer.createBot(botargs)
bot.once('spawn', () => {
bot.chat("/tp @s 4 76 5")
})
bot.on('physicTick', lookAtNearestPlayer)
bot.on('physicTick', () => {
bot.setControlState('jump', true)
})
bot.on('end', () => {
setTimeout(initBot, 5000)
})
}
function lookAtNearestPlayer() {
const playerFilter = (entity) => entity.type === 'player'
const playerEntity = bot.nearestEntity(playerFilter)
if (!playerEntity) return
const pos = playerEntity.position.offset(0, playerEntity.height, 0)
bot.lookAt(pos)
}
initBot()
Can anyone help, please