moeru-ai/airi · warning · Error

Player not found, stopped following

Error message

Player not found, stopped following

What it means

Thrown inside followPlayer() in the FollowCommand plugin. On each tick where state.following is set, it reads bot.bot.players[username]?.entity. If the followed player's entity is gone (player logged off, moved out of render distance, or despawned), it clears state.following and throws. The throw propagates out of the tick handler, so the follow silently stops (state cleared) and the error surfaces in the tick error path.

Source

Thrown at integrations/minecraft/src/plugins/follow.ts:37

        state.following = username
        logger.withFields({ username }).log('Starting to follow player')
        followPlayer()
      }

      function stopFollow(): void {
        state.following = undefined
        logger.log('Stopping follow')
        bot.bot.pathfinder.stop()
      }

      function followPlayer(): void {
        if (!state.following)
          return

        const target = bot.bot.players[state.following]?.entity
        if (!target) {
          state.following = undefined
          throw new Error('Player not found, stopped following')
        }

        const { x: playerX, y: playerY, z: playerZ } = target.position

        bot.bot.pathfinder.setMovements(state.movements)
        bot.bot.pathfinder.setGoal(new goals.GoalNear(playerX, playerY, playerZ, options?.rangeGoal ?? 1))
      }

      bot.onCommand('follow', (ctx) => {
        const username = ctx.command!.sender
        if (!username) {
          throw new Error('Please specify a player name!')
        }

        startFollow(username)
      })

      bot.onCommand('stop', () => {

View on GitHub (pinned to 27111382b4)

Solutions

  1. Wrap the follow command call (or the tick handler) in try/catch to report 'lost player' gracefully instead of an uncaught throw.
  2. Re-issue 'follow <name>' once the player is back in range.
  3. Check bot.players[name]?.entity existence before starting follow.
  4. Consider periodic re-validation and a cooldown before clearing the target.

Example fix

// before
//   function followPlayer(): void {
//     const target = bot.bot.players[state.following]?.entity
//     if (!target) {
//       state.following = undefined
//       throw new Error('Player not found, stopped following')
//     }
//     ...
//   }
//
// after
//   function followPlayer(): void {
//     const target = bot.bot.players[state.following]?.entity
//     if (!target) {
//       state.following = undefined
//       logger.log(`Stopped following: target no longer visible`)
//       return
//     }
//     ...
//   }
Defensive patterns

Strategy: try-catch

Validate before calling

// Guard the follow target before relying on it each tick:
// const target = bot.bot.players[state.following]?.entity
// if (!target) { state.following = undefined; logger.log('follow target lost'); return }

Type guard

function hasEntity(p: unknown): p is { entity: object } {
  return !!p && typeof p === 'object' && !!(p as any).entity
}

Try / catch

// Wrap the follow tick so a lost target does not crash the tick loop:
// try { followPlayer() }
// catch (e) { logger.log('follow error:', errorMessageFrom(e)) }

Prevention

When it happens

Trigger: The followed player disconnects from the server; the player moves beyond the server's entity tracking radius so bot.players[name].entity becomes undefined; the player enters a different dimension; the player is far enough that the server stops sending entity data.

Common situations: Long follow sessions where the target logs out; target teleporting across dimensions; target using /vanish or similar; high-latency connection dropping entity updates.

Related errors


AI-assisted analysis of moeru-ai/airi@27111382b4 (2026-08-12). Data as JSON: /api/errors/4a5b7dca15f88c59. Report an issue: GitHub.