title: I want to log every message from one server to one file but i gets error
body: <p>I want to log every message from one server to one file but i get error can someone help me please</p>
  <p><strong>Code</strong></p>
  <pre><code>@client.event
  async def on_message(message):
      async for message in message.channel.history(limit=1):
          file1 = open(&quot;MyFile.txt&quot;,&quot;a&quot;)
          file1.write(&quot;msg: &quot;+str(message.content)+&quot; &quot; +str(message.channel)+&quot; &quot;+str(message.author))
          file1.close()
  </code></pre>
  <p><strong>Error</strong></p>
  <pre><code>Traceback (most recent call last):
    File &quot;C:\Users\vikto\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\discord\client.py&quot;, line 343, in _run_event
      await coro(*args, **kwargs)
    File &quot;c:\Users\vikto\OneDrive\Desktop\selfbot\main.py&quot;, line 73, in on_message
      file1.write(&quot;msg: &quot;+str(message.content)+&quot; &quot; +str(message.channel)+&quot; &quot;+str(message.author))
    File &quot;C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.9_3.9.1776.0_x64__qbz5n2kfra8p0\lib\encodings\cp1252.py&quot;, line 19, in encode
      return codecs.charmap_encode(input,self.errors,encoding_table)[0]
  UnicodeEncodeError: 'charmap' codec can't encode characters in position 39-40: character maps to &lt;undefined&gt;
  Ignoring exception in on_message
  Traceback (most recent call last):```
  </code></pre>