Determining when player joins a new team

I’m trying to figure out how to determine when a client joins a new team.

Right now, I’m pulling the t\x\ value out of the ClientUserinfoChanged string and comparing it to what I already have stored for the client:

// ClientUserinfoChanged: 2 n\Test\t\3\model\ranger/pm\hmodel\ranger/pm\c1\4444\c2\5\hc\100\w\0\l\0\rt\3\st\0

// If client joined a different team, update team number
if( cl->teamNum != team ) {
 Com_Printf("\n\n\nDEBUG [%s] joining new team: [%i] old team: [%i]\n\n\n", cl->name, team, cl->teamNum);
 cl->teamNum = team;

However, it’s a little buggy with AI bots when a map starts. So, I was wondering if there’s a more reliable method for determining when a client joins a team different from the one they’re on?

Instead of using a client variable (cl), search for another, like entity (ent).
This will allow you to determine if the entity is a client (real human or alien player), or not client (bot).