title: Handling errors with the Discord API (on_error)
body: <p>I'm starting with Python and I'm currently working on a Discord bot with the API. So far so good, everything works. Now, I'm looking to host the script on a server without the console, which means I want the output to go in a file instead of in the console. I have the following currently working:</p>
  
  <pre class="lang-py prettyprint-override"><code>import discord
  import logging
  
  logging.basicConfig(filename='.\output.log', filemode='w', level=logging.INFO, format='%(asctime)s:%(levelname)s:%(message)s')
  
  xzbot = discord.Client()
  
  # logging when the bot starts
  @xzbot.event
  async def on_ready():
   logging.info('Logged in as ' + xzbot.user.name + ' (' + xzbot.user.id + ')\n')
  </code></pre>
  
  <p>So this code will put any warnings and infos in output.log. With that said, it doesn't work with exceptions raised by the Discord.py such as "Permissions denied" when the bot is trying to send a message without having the permissions.</p>
  
  <p>There is a built-in function in the Discord API to handle that:</p>
  
  <pre class="lang-py prettyprint-override"><code>discord.on_error(event, *args, **kwargs)
  </code></pre>
  
  <p>So I can call this function this way:</p>
  
  <pre class="lang-py prettyprint-override"><code>async def xzbot.on_error(event, *args, **kwargs):
   pass
  </code></pre>
  
  <p>Now, I tried doing something with <code>event</code>, <code>*args</code> or <code>**kwargs</code> but I need some help here to get that in a format where I can just use <code>logging.warning()</code>. All I'm able to get is <code>object</code> as a result of a <code>print(*args)</code> and I don't know how to format that properly.</p>