Count time between messages with discord.js and replit database

168 views Asked by At

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

1

There are 1 answers

10
MrMythical On BEST ANSWER

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

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