Getting RAP function keeps looping through same cursors? (Node.js)

Hello,

I have a discord bot for Roblox stuff, and I’m making a command where you can get the RAP of a specified user. Problem is, the function I used was based off Luau coding Get the player's RAP - #13 by Forummer
The problem is, whenever the specified user has a next cursor, it keeps looping the cursor forever. I’ve tried to check if the cursor was empty, or if the cursor was the same as the next one, or if the next one was the same as the previous. Some of them worked for some of the issues I was facing, especially with inventories with no next cursor.
Here’s the script:

        const firs_ = await message.reply("Calculating...")
        async function getRap(userId, RAP, cursor) {
          const RAP_T = []
          RAP = RAP || 0
          cursor = cursor || ''
          console.log(cursor, RAP)
          try {
              const response = await   fetch('https://inventory.roproxy.com/v1/users/' + userId + '/assets/collectibles?sortOrder=Asc&limit=100&cursor=' + cursor, {
                method: 'GET',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json'
                }
            })
            const result = await response.json()
            for (let i of result['data']) {
              if (i.recentAveragePrice) {
                  RAP += i.recentAveragePrice
              }
            }
            firs_.edit("Calculating... Current RAP: " + RAP)
            console.warn("Current RAP is", RAP)
            if (cursor !== result['nextPageCursor'] && result['nextPageCursor'] !== '' && result['nextPageCursor'] !== result['previousPageCursor']) {
                cursor = result['nextPageCursor']
                getRap(userId, RAP, cursor)
            } else {
                RAP_T.push(RAP)
                console.log("Finished calculating!")
                return RAP_T;
            }
          } catch(err) {console.warn("Error..", err); await message.reply("Error occured while calculating rap!"); RAP_T.push(0)}
        return RAP_T;
        }
        const args = message.content.split(' ')
        let _RBX_ID = args[1]
        if (isNaN(Number(_RBX_ID))) {
            const user_i = await stuffer.getIdFromUsername(_RBX_ID)
            _RBX_ID = user_i
        }
        const RAP_T = await getRap(_RBX_ID);
        await message.reply("**" + await stuffer.getUsernameFromId(_RBX_ID) + "** has " + RAP_T[0] + "$ RAP!")
    }

image
is the same cursor as:
image

Nevermind, fixed. I just made an object which had all next cursors and checked if the cursor was a duplicate.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.