In this case use : ON *:DISCONNECT: { } event, the on part event does not trigger while u disconnect from an server and i am sure that ON EXIT is not useful here.
Be careful that in the ON *:DISCONNECT: { } event you must add an loop to track down the channels that you are in using the $chan identifier.
e.g:
ON *:DISCONNECT: {
var %t = $chan(0)
var %i = 1
while (%i <= %t) {
var %c = $chan(%i)
var %tot = $addtok(%tot,%c,44)
inc %i
}
echo -a Disconnected from $server IRC Server, you were into the: $iif(%tot,$v1,None) channel(s).
}
/help on disconnect
/help $chan (it has 2, read both to understand)