Its silly but believe it or not the bot doesnt know its own nickname, as a result, you have to from the start, monitor the bots nickname, in a variable or some other method.

if (($2 == KICK) && ($4 == %variable)) {
sockwrite -n $sockname JOIN $3
}


Where you replace %variable with the one that is storing your bots nickname, also you might concider adding some 'protection' to stop the bot rejoining after X times.

You can track the nickname using, for example:

if (($2 == NICK) && (*.dal.net* iswm $1)) {
set %variable $remove($3,:)
}

$1 being the server you are currently connected too, and *dal.net* being something that is GUARENTEED to be present in every server address.

Eamonn.