未处理的拒绝错误:缺少必需的参数

时间:2021-04-15 17:59:18

标签: node.js

所以我使用了名为 revertranks.js 的文件,并尝试使用 node revertranks.js 运行它。

当我运行它时,会出现以下错误:

“未处理的拒绝错误:缺少必需的参数”

我想知道为什么会发生这种情况,所以我查看了该网站并尝试了其他解决方案,但是都没有奏效。使错误消失的一个实际上只是使代码停止。

代码如下:

 * About:
 * Reverts all rank change actions of a group after a specified date, with the option to filter by user.
 */

// Settings
const cookie = process.env.Cookie || '' // Roblox account .ROBLOSECURITY cookie
const options = {
  group: (process.env.GroupId), // Group ID
  userId: (process.env.AA1), // Revert rank changes made by this specified user - NOTE: When <= 0 any rank changes will be reverted
  afterDate: new Date('2021-01-01 00:00 CDT') // Date after which any rank changes will be reverted
}

// Dependencies
const rbx = require('noblox.js')
const logUpdate = require('log-update')

// Main
let scanning = true
const logItems = {
  scanned: 0,
  filtered: 0,
  reverted: 0,
  failed: 0
}

async function getAuditLogPage (getAuditLogOptions, cursor) {
  getAuditLogOptions.cursor = cursor || ''

  const auditLogPage = await rbx.getAuditLog(getAuditLogOptions)

  return auditLogPage
}

function filterAuditLogItems (auditLogItems) {
  const filteredAuditLogItems = []

  for (const auditLogItem of auditLogItems) {
    if (Date.parse(auditLogItem.created) > options.afterDate) {
      logItems.filtered++
      filteredAuditLogItems.push(auditLogItem.description)
    }
  }

  return filteredAuditLogItems
}

async function revertAuditLogItems (auditLogItems) {
  for (const auditLogItem of auditLogItems) {
    const setRankOptions = {
      group: options.group,
      target: auditLogItem.TargetId,
      roleset: auditLogItem.OldRoleSetId
    }

    await rbx.setRank(setRankOptions)
      .then(() => {
        logItems.reverted++
      })
      .catch((e) => {
        logItems.failed++
      })
  }
}

rbx.setCookie(process.env.Cookie)
  .then(async () => {
    console.time('Time taken')

    const logUpdater = setInterval(() => {
      logUpdate(`Scanned: ${logItems.scanned}\nFiltered: ${logItems.filtered}\nReverted: ${logItems.reverted}\nFailed: ${logItems.failed}`)

      if (!scanning && logItems.reverted + logItems.failed === logItems.filtered) {
        clearInterval(logUpdater)

        console.timeEnd('Time taken')
      }
    }, 100)

    const getAuditLogOptions = {
      group: options.group,
      actionType: 'changeRank',
      userId: options.userId > 0 ? options.userId : null,
      limit: 100
    }

    let auditLogPage = await getAuditLogPage(getAuditLogOptions)
    logItems.scanned += auditLogPage.data.length

    await revertAuditLogItems(filterAuditLogItems(auditLogPage.data))

    while (auditLogPage.nextPageCursor !== null && Date.parse(auditLogPage.data[auditLogPage.data.length - 1].created) > options.afterDate) {
      auditLogPage = await getAuditLogPage(getAuditLogOptions, auditLogPage.nextPageCursor)
      logItems.scanned += auditLogPage.data.length

      await revertAuditLogItems(filterAuditLogItems(auditLogPage.data))
    }

    scanning = false
  
  })

请帮帮我,我需要这个来使用机器人恢复网站上的操作。

这是自从有人问起的错误信息:https://imgur.com/a/U9HJW7O

我为之前的消息道歉,我放了一些我正在试验的代码。

0 个答案:

没有答案