During ON JOIN there is only you in the nicklist, and you cannot kick until you receive the OP status. So better is to hook the ON OP event, and do the scan at that time.

Since the nicklist exists, and you are not checking the userid for nick!bad-word@company.com you do not need the /who reply.

If I were doing this, I would do it so that the list is not kept on disk, because you are reading a disk file many times for each nick. But, to keep it similar to this way, I make some changes to be more efficient. For example, the file is not changing, so you do not need to keep counting how many lines there are. Also, you do not need to read the same line from the disk file 2 times in order to compare the text against 2 things.

Also I changed it so that it uses /return instead of /halt so that you can check all the nicklist at the same time instead of stopping before finishing.

Also, where you see me using $nick($chan,%i,r) that is how it sees each nick in the nicklist, and the 'r' means 'regular nicks who have no status. If you want to kick ops and voices too, change the 'r' to 'a' which means 'all nicks'. If you want to check both regular nicks and voices, then change 'r' to 'rv'.

You can list the channelname(s) as I did, or to do this in all channels where you are OP, just change that line to be

on *:OP:#:{



Code
on *:OP:#channelname1,#channelname2:{
  if ($opnick != $me) return
  var %i 1
  while ($nick($chan,%i,a) != $null) {
    noop $BaneaUsuarios( $v1 , $chan )
    inc %i
  }
}

alias BaneaUsuarios {
  var %cuentaNicks = 1 , %badwords_total $lines(patrones.txt) , %except_total $lines(patrones-exceptuados.txt)
  while (%cuentaNicks <= %badwords_total) {
    var %linetext $read(patrones.txt,nt,%cuentaNicks)
    if (%linetext isin $1) || (%linetext iswm $1) {
      var %cuentaExcepciones = 1

      while (%cuentaExcepciones <= except_total) {
        var %except_linetext $read(patrones.txt,nt,%cuentaNicks)
        if (%except_linetext isin $1) || (%except_linetext iswm $1) {
          ;halt
          return
        }
        inc %cuentaExcepciones
      }

      ban $2 $1 $+ !*@* | kick $2 $1 1Su nick no es el mas adecuado para la tematica del canal 4 $chan 1Por Favor, cambielo. 4Gracias.
      return
      ;halt
    }
    inc %cuentaNicks
  }

}