即使我不想解析,node.js为什么也会给我一个解析错误?
我以某种方式遇到了这个错误:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我没有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)
withdb.get(607341305994936320)
ordb.get('607341305994936320')
and don't get any errors, then maybe you should rethink the linevar 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).我能够找到答案。由于某种原因,我需要在变量Uservotec上使用json.stringify ...而不是第28行中的代码,请使用以下操作:
或者,您可以将用户变量转换为JavaScript对象。
感谢您为帮助我找到答案的帮助。
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:
Alternatively, you could convert the user variable to a javascript object.
Thank you for everyone's help in helping me find an answer.