[edit: removed the lock suggestion]It would be something like these..
[color:brown]on *:join:#:{ if ($nick == $me) && ($istok(%chans,$chan,32)) { part } }[/color]
or
[color:brown]on me:*:join:#:{ if ($istok(%chans,$chan,32)) { part } }[/color]
You'd fill
%chans with "
#channel1 #channel2 #channel3 ... #channelN".
Your current script fails because..
1) Your
/if statement doesn't check if
$chan is an existing item from the list on
%chans. Instead, it checks if
$chan is different (
!=) than the whole list on
%chans, which doesn't make sense;
2) Your
/part command is not part of the
/if statement (no
{ } brackets nor both sentences in the same line), causing the script to always leave any channel you join.