我使用 mineflayer 为我的 Aternos 服务器制作了一个简单的 AFK 机器人。当从我的计算机本地运行时,它似乎工作正常。但是当我尝试使用渲染来部署它时,它只是不断离开和加入。 这是我的代码:
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()
有谁可以帮忙吗
如果您使用免费计划,您的 Web 应用程序将在 15 分钟没有请求后“停止运行”。保持其唤醒状态的一种方法是使用 cron-job.org,每 10 分钟 ping 一次 Web 应用程序的 URL。