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’, }
Advertisement
Answer
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.