Ask coding questions

← Back to all posts
What does db.get() return?
ThatGhost (4)

So, here is the background on my issue:
I am making a discord bot for my server. It has a dashboard and everything.

I am making a captcha system right now, and for some reason, if o do:

// IF they typed the wrong verification code.
if(userv !== code) return message.reply("incorrect captcha!");

if the user types the wrong captcha, it sends the message, but, if the user types the right captcha, it still sends the message.

i define the code variable the line before, this is where the issue lies.

const code = db.get(`captcha_${}`);

I am using replit's build in db, i tried logging it.

// Attempt 1
console.log(code + " & " + userv);
//Result: [objectPromise] & the captcha

// Attempt 2
//Result: {}

we send in numbers and get whatever it returns, but what does it return?

if its a promise, all i need to do is make the function asynchronous and add resolve it using await

but if its an object i need to somehow view the json object.

if you need my code, go in the commands folder and open verify.js

Answered by Coder100 (18813) [earned 5 cycles]
View Answer
Coder100 (18813)

db.get returns a promise, meaning it takes time for the function to execute.
What you have to do is something like this:

client.on("message", async(msg) => {
  let val = await db.get("value");;

it is required for the await syntax.

ThatGhost (4)

@Coder100 ok, thats what i thought. Thanks!