Added error handling in bot.js

Added an onError function to write the error message to a log file. Will be useful for bot debugging.