title: How can I have a DJS bot check through a DB of multiple ranks and only promote to the next rank?
body: <p>Currently working on a discord.js bot and running into issue while trying to create a ranking system for the server to use based off XP added when chatting. However I am running into the problem a problem when having multiple ranks.</p>
  <p>The rank database has 4 different ranks starting at a requirement of 1000xp and increasing 1000 per next rank.</p>
  <p>As this bot is intended to be used in multiple servers, users are associated by the server ID that they share with the bot, as such all the ranks are also associated based off of the Server ID in which the role is created/used.</p>
  <p>As such the bot first Checks the XP table to pull that users CURRENT xp, after it will check to see which server the user is in within the user table, and then based off of that it will then pull all the ranks with a matching Server ID from the rank table.</p>
  <p>This is next part is where I am having the issue,</p>
  <p>as in the code you'll see that the bot is checking if the CURRENT xp is greater than or equal too the XP within the rank table matching the ranks associated with said server, when the user has 1001+ XP it will constantly try to add a new rank regardless of the next ranks XP requirement. (Example user has 1001xp - next rank is 2000xp bot still tries to promote)</p>
  <pre><code> con.query(`SELECT * FROM xp WHERE ID = ${message.author.id}`, (err, rows) =&gt; {
      if (err) return console.log(err)
      let exp = rows[0].XP
      //finding user in db to get sid
      con.query(`SELECT * FROM users WHERE ID = ${message.author.id}`, (err, rows) =&gt; {
          if (err) return console.log(err)
          let si = rows[0]
          //finding next rank based off xp/sid
          con.query(`SELECT * FROM rank WHERE DID = ${si.SID}`, (err, rows) =&gt; {
              console.log(rows)
              if (err) return console.log(err)
              let srl = rows[0]
  
              if(exp &gt;= srl.xp){
                  console.log(&quot;promo&quot;)
              }
              if(exp &lt;= srl.xp){
                  console.log(&quot;No&quot;)
              }
              
              //defining role to add
              let prole = member.guild.roles.cache.find(r =&gt; r.id === srl.rid)
  
          })
      })
  })
  </code></pre>
  <p>Previously I have added <code>console.log(rows)</code> at each query point and all the information is being found correctly however I think its the way I am trying to execute the actual promotion, I have attempted to search through Stackoverflow, google, and youtube for some answers before coming here and havent been able to find success.</p>
  <p>The goal I want here is the bot will recognize based off the DB information what the next rank is and the required XP to achieve it. I already have the code prepared to add the rank and update the dbs with the new information however I need to get past this current speedbump.</p>
  <p>Edit</p>
  <p>Think I should include the abreviations</p>
  <pre><code>exp = users current xp
  si = users associated server ID
  srl = Server Ranked Role
  
  si.SID = Just actually pulling the server ID from the SID column of the DB
  srl.xp = The actual required XP to promote to that rank. 
  </code></pre>