即使我不想解析,node.js为什么也会给我一个解析错误?

发布于 2025-02-09 00:33:09 字数 1373 浏览 1 评论 0原文

我以某种方式遇到了这个错误:

UnhandledPromiseRejectionWarning: SyntaxError: Failed to parse value of 607341305994936320votecrate, try passing a raw option to get the raw value

而且我不知道为什么...有人可以解释这个错误意味着什么或告诉我代码中的错误?谢谢!

const express = require('express');
const app = express();
const path = require('path');
const port = 300;
const Database = require("@replit/database")
const db = new Database()
const Topgg = require("@top-gg/sdk")

const topggauth = process.env['topgg']
const webhook = new Topgg.Webhook(topggauth)

app.post("/dblwebhook", webhook.listener(vote => {
  const user = vote.user

  if (vote.type == 'test'){
    console.log(vote)
  }
  if (vote.type){
    const weekend = vote.isWeekend
    function weekendcheck() {
      if (weekend == "true"){
        return 2
      }
      if (weekend == "false"){
        return 1
      }
    }
    var uservotec = (user + "votecrate")
    console.log(uservotec)
    db.get(uservotec).then(value => {
      if (!value){
        db.set(uservotec, weekendcheck())
      }
      if (value){
        db.set(uservotec, (weekendcheck() + Number(value)))
      }
    });
  }
}))

app.listen(port, () => console.log('App port online!'));

谢谢!请注意,投票变量的JSON格式类似:

{ 用户:'607341305994936320', 类型:“测试”, 询问: '', bot:'981329232456192100',, isweekend:“ false”, }

I'm somehow getting this error:

UnhandledPromiseRejectionWarning: SyntaxError: Failed to parse value of 607341305994936320votecrate, try passing a raw option to get the raw value

And I don't know why... Could anyone explain what this error means or tell me the error in my code? Thanks!

const express = require('express');
const app = express();
const path = require('path');
const port = 300;
const Database = require("@replit/database")
const db = new Database()
const Topgg = require("@top-gg/sdk")

const topggauth = process.env['topgg']
const webhook = new Topgg.Webhook(topggauth)

app.post("/dblwebhook", webhook.listener(vote => {
  const user = vote.user

  if (vote.type == 'test'){
    console.log(vote)
  }
  if (vote.type){
    const weekend = vote.isWeekend
    function weekendcheck() {
      if (weekend == "true"){
        return 2
      }
      if (weekend == "false"){
        return 1
      }
    }
    var uservotec = (user + "votecrate")
    console.log(uservotec)
    db.get(uservotec).then(value => {
      if (!value){
        db.set(uservotec, weekendcheck())
      }
      if (value){
        db.set(uservotec, (weekendcheck() + Number(value)))
      }
    });
  }
}))

app.listen(port, () => console.log('App port online!'));

Thanks! Please note that the vote variable is in json format similar to this:

{
user: '607341305994936320',
type: 'test',
query: '',
bot: '981329232456192100',
isWeekend: 'false',
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

情绪操控生活 2025-02-16 00:33:09

我没有node.js的经验,但是似乎您正在尝试使用ID从数据库中接收数据,但意外地将VARCHAR传递给了INT列。

如果您替换 db.get(uservotec) db.get(607341305994936320) db。 get('607341305994936320'),并且不要遇到任何错误,那么也许您应该重新考虑行var uservotec =(user +“ fotecrate”),因为它是在凝聚float/int 带有字符串votecrate ”的值,“ 607341305994949494936320VoteCrate ”,这不是有效的 id (也许我是错误的假设,但我希望这会有所帮助,并可以随意寻求更好的解释)。

I'm inexperienced with node.js but it seems like you're trying to receive data from the database using an ID, but accidentally passing a varchar to an INT column.

If you replace db.get(uservotec) with db.get(607341305994936320) or db.get('607341305994936320') and don't get any errors, then maybe you should rethink the line var uservotec = (user + "votecrate") because it is concatenating the float/int value with the string "votecrate" resulting in "607341305994936320votecrate" which isn't a valid ID (maybe I'm wrongly assuming but I hope this helps and feel free to ask for a better explanation).

心的位置 2025-02-16 00:33:09

我能够找到答案。由于某种原因,我需要在变量Uservotec上使用json.stringify ...而不是第28行中的代码,请使用以下操作:

var uservotec = JSON.stringify(user + "votecrate")

或者,您可以将用户变量转换为JavaScript对象。

var user = JSON.parse(vote.user)

感谢您为帮助我找到答案的帮助。

I was able to find an answer. For some reason, I needed to use JSON.stringify on the variable uservotec... Instead of the code in line 28, use this:

var uservotec = JSON.stringify(user + "votecrate")

Alternatively, you could convert the user variable to a javascript object.

var user = JSON.parse(vote.user)

Thank you for everyone's help in helping me find an answer.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文