title: Command working fine but I get error whenever I dm the bot. [discord.py]
body: <p>so I have this code for my prefix. I have no problem with it. It's working fine, but whenever I message my bot it gives me this error. Is there anyway to ignore this or fix it? Thanks</p>
  <pre><code>with open(&quot;prefix.json&quot;) as f:
      prefixes = json.load(f)
      default_prefix = &quot;?&quot;
  
  def prefix(client, message):
      id = message.guild.id
      return prefixes.get(id, default_prefix)
  
  client = commands.Bot(command_prefix=prefix)
  
  @client.command(name=&quot;Prefix&quot;, aliases=[&quot;prefix&quot;, &quot;setprefix&quot;])
  @commands.has_permissions(manage_guild=True)
  async def _prefix(ctx, new_prefix):
      msg = ctx.message
      prefixes[msg.guild.id] = new_prefix
      with open(&quot;prefix.json&quot;, &quot;w&quot;) as f:
          json.dump(prefixes, f, indent=4)
  
  Error:
  Ignoring exception in on_message
  Traceback (most recent call last):
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\client.py&quot;, line 312, in _run_event
      await coro(*args, **kwargs)
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py&quot;, line 930, in on_message
      await self.process_commands(message)
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py&quot;, line 926, in process_commands
      ctx = await self.get_context(message)
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py&quot;, line 842, in get_context
      prefix = await self.get_prefix(message)
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\ext\commands\bot.py&quot;, line 787, in get_prefix
      ret = await discord.utils.maybe_coroutine(prefix, self, message)
    File &quot;C:\Users\user\AppData\Local\Programs\Python\Python38-32\lib\site-packages\discord\utils.py&quot;, line 317, in maybe_coroutine
      value = f(*args, **kwargs)
    File &quot;C:/Users/user/Desktop/test.py&quot;, line 14, in prefix
      id = message.guild.id
  AttributeError: 'NoneType' object has no attribute 'id'
  </code></pre>