title: Counting invites for new members
body: <p>I'm trying to get the possible invite for users that join on discord But it simply doesn't work and I don't know why. I'd expect it to output "couldn't find invite" for bots but instead it says nothing at all, not for users, nor bots. It should work to my knowledge. It scans every invite in the servers and stores them, then it checks if it goes up on the user that joins and outputs the embed.</p>
  
  <pre><code>    def __init__(self, bot):
          self.bot.loop.create_task(self.get_invites())
  
      async def get_invites(self):
              for guild in self.bot.guilds:
                  try:
                      guild_invites = {}
                      invites = await guild.invites()
                      for invite in invites:
                          guild_invites[invite.code] = invite
                      self.invites[guild] = guild_invites
                  except discord.errors.Forbidden:
                      pass
  
  
      async def find_possible_invites(self,guild):
          i = 1
          while i &lt; 11:
              new = await guild.invites()
              res = []
              for invite in new:
                  try:
                      old_uses = self.invites[guild][invite.code].uses
                  except KeyError:
                      self.invites[guild][invite.code] = invite
                      if invite.uses &gt;= 1:
                          res.append(invite)
                      continue
                  new_uses = invite.uses
                  if old_uses &lt; new_uses :
                      self.invites[guild][invite.code] = invite
                      res.append(invite)
  
              if res == []:
                  await asyncio.sleep(3)
                  i+=1
              else:
                  break
          return res
  
      @commands.Cog.listener()
      async def on_member_join(self,member):
          server = await self.bot.get_guild(SERVER_ID)
          possible_invites = await self.find_possible_invites(server)
          channel = self.bot.get_channel(CHANNEL_ID)
  
          whtspace= "** **"
          embed = discord.Embed(color=0x21d3f3)
          embed.title = "Member Joined!"
          embed.add_field(name="Name",value=str(member))
          embed.add_field(name="User ID:",value=member.id)
          if len(possible_invites) == 1:
              embed.add_field(name="Invite used",value=possible_invites[0].url,inline=True)
              embed.add_field(name="Invite created by",value=str(possible_invites[0].inviter),inline=True)
              embed.add_field(name="Number of uses",value=str(possible_invites[0].uses),inline=True)
  
          elif len(possible_invites) &gt; 1:
              embed.add_field(name="Possible invites used:",value=whtspace,inline=False)
              for i in possible_invites:
                  embed.add_field(name=whtspace,value=i.url,inline=False)
          else:
              await channel.send("Invite used could not be detected")
  
          await channel.send(embed=embed)
  </code></pre>