This script isn't fixable as it doesn't make sense. There are syntax errors, and the code in the elseif section will never execute as the bot won't see the text if it's not in the channel. This is a rewrite based on what I believe you require:
Code:
on *:text:!leave:#: {
  if ($chan isin %botchans) {
    %botchans = $remtok(%botchans, $chan, 1, 32)
    msg $chan Leaving channel: Requested by $nick
    .timer 1 1 part $chan
  }
}


When someone types !leave in a channel if the channel is in the %botchans list the bot will remove the channel from the list and leave the channel.