How to make the bot not check the distance from itself to itself?

All AI bots using this script have the same tag. How to make the bot not check the distance from itself to itself?

using System.Collections;
 using System.Collections.Generic;
 using System.Data;
 using UnityEditorInternal;
 using UnityEngine;
 using UnityEngine.AI;
 using UnityEngine.SceneManagement;
 
 public class NewBehaviourScript : MonoBehaviour
 {
 
     NavMeshAgent _navMeshAgent;
 
     private GameObject player;
     private GameObject ai;
 
     private float aiPlayerDist;
     private float aiAiDist;
 
     void Start()
     {
         _navMeshAgent = this.GetComponent<NavMeshAgent>();
 
         if(_navMeshAgent == null)
         {
             Debug.LogError("ERROR" + gameObject.name);
         }
     }
 
     void Update()
     {
         SetDestination();
     }
 
     private void SetDestination()
     {
         player = GameObject.FindGameObjectWithTag("Player");
         ai = GameObject.FindGameObjectWithTag("Ai");
 
         aiPlayerDist = Vector3.Distance(player.transform.position, transform.position);
         aiAiDist = Vector3.Distance(ai.transform.position, transform.position);
 
         if (player != null || ai != null)
         {
             if (aiPlayerDist > aiAiDist)
             {
                Vector3 targetVector = ai.transform.position;
                _navMeshAgent.SetDestination(targetVector);
             }
             else if (aiPlayerDist < aiAiDist)
             {
                 Vector3 targetVector = player.transform.position;
                 _navMeshAgent.SetDestination(targetVector);
             }
         }
 
         Debug.Log(aiAiDist);
 
     }
 }

Check the objects you have found are not the same as the one running this script?

if (ai.transform != this.transform)

Do it this way:

foreach( var nextComponent in SomeComponentType.Instances )
{
    if( nextComponent!=this )
    {
        /* not me */
    }
}

More on how to create that SomeComponentType.Instances in code below.

Enemy.cs:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

[DisallowMultipleComponent]
[RequireComponent( typeof(NavMeshAgent) )]
public class Enemy : MonoBehaviour
{
    public static List<Enemy> Instances = new List<Enemy>(1);
    [SerializeField] NavMeshAgent _navMeshAgent;// just fill manually and be done with it
    const float _aiTickRate = 0.1f;// [seconds]
    void OnEnable ()
    {
        Instances.Add( this );
        InvokeRepeating( nameof(AiTick) , _aiTickRate , _aiTickRate );
    }
    void OnDisable ()
    {
        Instances.Remove( this );
        CancelInvoke( nameof(AiTick) );
    }
    void AiTick ()
    {
        Vector3 myPosition = transform.position;

        // find nearest player:
        Player nearestPlayer = null;
        float nearestPlayerDistance = float.MaxValue;
        Vector3 nearestPlayerPosition = Vector3.zero;
        foreach( var nextPlayer in Player.Instances )
        {
            Vector3 nextPos = nextPlayer.transform.position;
            float nextDist = Vector3.Distance( myPosition , nextPos );
            if( nextDist<nearestPlayerDistance )
            {
                nearestPlayer = nextPlayer;
                nearestPlayerDistance = nextDist;
                nearestPlayerPosition = nextPos;
            }
        }

        // find nearest enemy:
        Enemy nearestOtherEnemy = null;
        float nearestOtherEnemyDistance = float.MaxValue;
        Vector3 nearestOtherEnemyPosition = Vector3.zero;
        foreach( var nextEnemy in Enemy.Instances )
        {
            if( nextEnemy!=this )
            {
                Vector3 nextPos = nextEnemy.transform.position;
                float nextDist = Vector3.Distance( myPosition , nextPos );
                if( nextDist<nearestOtherEnemyDistance )
                {
                    nearestOtherEnemy = nextEnemy;
                    nearestOtherEnemyDistance = nextDist;
                    nearestOtherEnemyPosition = nextPos;
                }
            }
        }

        // decide what to do about it:
        if( nearestPlayer!=null )
        {
            _navMeshAgent.SetDestination( nearestPlayerPosition );
        }
    }
}

Player.cs:

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;

[DisallowMultipleComponent]
[RequireComponent( typeof(NavMeshAgent) )]
public class Player : MonoBehaviour
{
    public static List<Player> Instances = new List<Player>(1);
    [SerializeField] NavMeshAgent _navMeshAgent;// just fill manually and be done with it
    void OnEnable ()
    {
        Instances.Add( this );
    }
    void OnDisable ()
    {
        Instances.Remove( this );
    }
    void Update ()
    {
        
    }
}