This is what I did to detect the ! prefix.

Code:
 if $nick(#,$nick,!) { do stuff }
 


You can also use the other prefixes as well and use multiple prefixes at the same time i.e.: if $nick(#,$nick,!@+)

Side note: The following is a suitable replacement for the "on op" event if you need to look for the +a mode as well:

Code:
 
on *:rawmode:#: { 
  if ((($1 == +a) || ($1 == +o)) && ($2 == $me)) {  do stuff  }
}
 


That will check to see if you've been opped with ! or @ but $me can be replaced to check if others are opped.