title: discord.py: ideas on how to speed up the processing time of this command
body: <p>I have a command that finds the oldest and newest users in a server. It checks through every user, until it find all the nessesary information. It works fine until I use it in a server with 2000 users takes like 10 seconds to process and I can't use any other command with the bot furring that time.
  Code of the command:</p>
  <pre><code>    @commands.command()
      async def oldest(self, ctx, page: int=1):
          await oldest_newest(self, ctx, page, &quot;Oldest&quot;)
      # tnewest
      @commands.command()
      async def newest(self, ctx, page: int=1):
          await oldest_newest(self, ctx, page, &quot;Newest&quot;)
  
  async def oldest_newest(self, ctx, page, sort_type):
      page = abs(int(page))
      if page &gt; 99: page = 99
  
      x1 = x2 = x3 = x4 = x5 = x6 = x7 = x8 = x9 = x10 = None
      searchint = (page-1)*10
      for x in ctx.guild.members:
          if sort_type == &quot;Oldest&quot;: creation_pos = sum(m.created_at &lt; x.created_at for m in ctx.guild.members if m.created_at is not None) + 1
          if sort_type == &quot;Newest&quot;: creation_pos = sum(m.created_at &gt; x.created_at for m in ctx.guild.members if m.created_at is not None) + 1
          if creation_pos == searchint+1: x1 = x
          if creation_pos == searchint+2: x2 = x
          if creation_pos == searchint+3: x3 = x
          if creation_pos == searchint+4: x4 = x
          if creation_pos == searchint+5: x5 = x
          if creation_pos == searchint+6: x6 = x
          if creation_pos == searchint+7: x7 = x
          if creation_pos == searchint+8: x8 = x
          if creation_pos == searchint+9: x9 = x
          if creation_pos == searchint+10: x10 = x 
      
      members_sorted =[]
      if x1 is not None: members_sorted.append(x1)
      if x2 is not None: members_sorted.append(x2)
      if x3 is not None: members_sorted.append(x3)
      if x4 is not None: members_sorted.append(x4)
      if x5 is not None: members_sorted.append(x5)
      if x6 is not None: members_sorted.append(x6)
      if x7 is not None: members_sorted.append(x7)
      if x8 is not None: members_sorted.append(x8)
      if x9 is not None: members_sorted.append(x9)
      if x10 is not None: members_sorted.append(x10)
  
      cycle_int = 0
      output_string = &quot;&quot;
      for x in members_sorted:
          cycle_int = cycle_int + 1
          output_string += f&quot;**{cycle_int+((page-1)*10)}** - {x} - {x.created_at.strftime('%d/%m/%Y')}\n&quot;
  
      em = discord.Embed(color=self.client.Blue)
      em.add_field(name=f&quot;{sort_type} accounts in **{ctx.guild.name}**&quot;, value=output_string, inline=False)
  
      em.set_footer(text=f&quot;Page: {page}&quot;)
      em.timestamp = datetime.utcnow()
          
      await ctx.send(embed=em)
  </code></pre>
  <p>I'm fairly new to discord bots and learnt everything off YouTube or here. Though this is the first time I'm actually asking for help. Any ideas??</p>