Well uhh... the code you have says "when someone quits, and it's the bot, make the bot try and set a mode".... now how's it gonna set a mode if it's quit? you might want to go for an entire re-write there....