'Count time between messages with discord.js and replit database

I've been googling for a long time now and can't find a solution. My current code:

let end = new Date().getTime();
if(Msg == "test") {
  // ...
}
db.set("start", new Date().getTime());

If I try to send db.get("start") it will send

[object Promise]

If I try to send db.get("start") - end it will send

NaN

I wanna measure the time between previous message and last one(that was just sent) so my solution for it is using the data base to keep the time when the last one was sent. This worked back when I coded a bot in python but now in JavaScript I can't get it to work.

Can anyone please help?

p.s Msg = msg.content. Not that important but whatever



Solution 1:[1]

db.get() returns a promise, which you need to await

const start = await db.get("start")
console.log(start - end)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 MrMythical