First, in the amsg proc, there's no space inbetween the channel and the message (with the colon-prefix). $chan:$arg should be $chan :$arg
Secondly, the "list" of messages is not a proper list, and your script may break if there's any { or } characters within. The proper way of doing this is to use the list command to build/set the list.
Further, the code has some spurious global commands at aglobal context. This is not an error, but a pointless line of code that only makes the code harder to read.