title: UnboundLocalError: local variable 'msg' referenced before assignment. How to fix it?
body: <p>I'm getting count of messages from json file, but i have an error... And i do not know why. In this program bot has to send information about member in mention. If I write <code>msg = None</code> at the beginning of the code, it won't send like <code>&gt; messages = 10</code> it will send <code>messages = None</code></p>
  
  <p><strong><em>PROGRAM</em></strong></p>
  
  <pre><code>if args[0] == '!in':
      await client.delete_message(message)
      highclass = None
      gm = ""
      clan = None
      if (roleLeaders in message.author.roles or roleHunter in message.author.roles or roleDeputy in message.author.roles):
              for member in message.mentions:
                  user = member
                  userjoin = str(user.joined_at)
                  joinpars= userjoin.split()
                  join = joinpars[0]
                  msg1 = user_get_msg(member.id)
                  time1 = user_get_time(member.id)
                  s = str(msg1)
                  last = int(s[-1])
                  st = str(time1)
                  stm = time1 // 60
                  sth = stm // 60
                  std = sth // 24
                  if time1 &lt;= 60:
                      lastt = int(st[-1])
                      if lastt == 0:
                          time = '{0} секунд'.format(time1)
                      if lastt == 1 and not time1 == 11:
                          time = '{0} секунду'.format(time1)
                      if ((time1 &gt;= 11 and time1 &lt;= 19) or (lastt &gt;= 5 and lastt &lt;= 9)):
                          time = '{0} секунд'.format(time1)
                      if (lastt &gt;= 2 and lastt &lt;= 4) and not (time1 &gt;= 11 and time1 &lt;= 19):
                          time = '{0} секунды'.format(time1)
  
                  if time1 &lt;= 3600 and time1 &gt; 60:
                      lastt = int(str(stm)[-1])
                      if lastt == 0:
                          time = '{0} минут'.format(stm)
                      if lastt == 1 and not stm == 11:
                          time = '{0} минуту'.format(stm)
                      if ((stm &gt;= 11 and stm &lt;= 19) or (lastt &gt;= 5 and lastt &lt;= 9)):
                          time = '{0} минут'.format(stm)
                      if (lastt &gt;= 2 and lastt &lt;= 4) and not (stm &gt;= 11 and stm &lt;= 19):
                          time = '{0} минуты'.format(stm)
  
                  if time1 &lt;= 86400 and time1 &gt;3600:
                      lastt = int(str(sth)[-1])
                      if lastt == 0:
                          time = '{0} часов'.format(sth)
                      if lastt == 1 and not sth == 11:
                          time = '{0} час'.format(sth)
                      if ((sth &gt;= 11 and sth &lt;= 19) or (lastt &gt;= 5 and lastt &lt;= 9)):
                          time = '{0} часов'.format(sth)
                      if (lastt &gt;= 2 and lastt &lt;= 4) and not (sth &gt;= 11 and sth &lt;= 19):
                          time = '{0} часа'.format(sth)
  
                  if time1 &gt;= 86400:
                      lastt = int(str(std)[-1])
                      if lastt == 0:
                          time = '{0} дней'.format(std)
                      if lastt == 1 and not std == 11:
                          time = '{0} день'.format(std)
                      if ((std &gt;= 11 and std &lt;= 19) or (lastt &gt;= 5 and lastt &lt;= 9)):
                          time = '{0} дней'.format(std)
                      if (lastt &gt;= 2 and lastt &lt;= 4) and not (std &gt;= 11 and std &lt;= 19):
                          time = '{0} дня'.format(std)
                  if msg1 &gt;= 0:
                      if last == 0 or msg1 == 0:
                          msg = '{0} записок'.format(msg1)
                      if msg1 == 1 or (last == 1 and msg1 &gt;= 21):
                          msg = '{0} записку'.format(msg1)
                      if (msg1 &gt;= 2 and msg1 &lt;= 4) or (msg1 &gt;= 22 and msg1 &lt;= 24):
                          msg = '{0} записки'.format(msg1)
                      if (last &gt;= 5 and last &lt;= 9):
                          msg = '{0} записок'.format(msg1)
                  for role in member.roles:
                      with open('class.json', 'r') as roleread:
                          if role.id in roleread.read():
                              highclass = '&lt;@&amp;{0}&gt;'.format(role.id)
                      with open('clans.json', 'r') as fp:
                          if role.id in fp.read():
                              gm = '&gt; Является участником гильдии &lt;@&amp;{0}&gt;.'.format(role.id)
                              if roleGM in member.roles:
                                  gm = '&gt; Является **мастером** гильдии &lt;@&amp;{0}&gt;.'.format(role.id)
                  await asyncio.sleep(0.01)
                  await client.send_message(message.channel, 'Персонаж {0}:\n'
                                                             '&gt; Прибыл в город **{1}**;\n'
                                                             '&gt; Принимал участие в жизни города **{2}**;\n'
                                                             '&gt; Написал **{3}**;\n'
                                                             '&gt; Имеет класс {4};\n'
                                                             '{5}'.format(member.mention, join, time, msg, highclass, gm))
  </code></pre>
  
  <p><strong><em>ERROR</em></strong></p>
  
  <pre><code>File "soul.py", line 497, in on_message
  '{5}'.format(member.mention, join, time, msg, highclass, gm))
  UnboundLocalError: local variable 'msg' referenced before assignment
  </code></pre>
  
  <p>I've tried everything, what I could. Can somebody help me?</p>