Code:
 On *:Join:#: {
  if ($nick == $me) {    .timerAV 0 10 autovoice $chan  }
  else {    mode $chan +v $nick  }
}
On me:*:Part:#: { .timerAV off }
on *:quit: { .timerAV off }
on me:*:kick:3:{ .timerAV off }
on *:exit: { .timerAV off }
on @*:action:*:#:{
  if ($nick isreg $chan) mode $chan +v $nick 
}
On @*:Text:*:#: {
  if ($nick isreg $chan) mode $chan +v $nick 
}
alias autovoice {
  var %x = $nick($1,0,v)
  while (%x) && ($me isop $1) {
    if (($nick($1,%x,v).idle >= 1200) && ($nick($1,%x,v) != $me)) {
      msg $1 $nick($1,%x,v) You've been devoiced because you haven't been saying nothing for over 20 minutes now
      mode $1 -v $nick($1,%x,v)
    }
    dec %x
  }
}
 


Try this instead. It's close, but it only checks the nicks that are currently voiced, rather than all of the nicks.