DISCORD.JS - Variable Undefined, not sure why

Was using some example code that another user provided a while ago for a cooldown using quick.db.

The cooldown itself works fine, but the message which provides the amount of time left on the cooldown doesn’t work, time.days, time.hours etc are all undefined and I’m not sure why.


let ms = require(‘ms’)
let db = require(‘quick.db’)
//check if there is cooldown
const timeout = 604800000; // 7 days in milliseconds, change to the desired cooldown time, in milliseconds
const cooldown = await db.fetch(cooldown_Command-Name_${message.guild.id}_${message.author.id});

if (cooldown !== null && timeout - (Date.now() - cooldown) > 0) {
	const time = ms(timeout - (Date.now() - cooldown));
	message.channel.send(`Sorry you must wait **${time.days}d ${time.hours}h ${time.minutes}m ${time.seconds}s** before using this command again!`);
} else {

//code here that runs if there is no cooldown

// code put after no cooldown code, to set the cooldown
db.set(cooldown_Command-Name_${message.guild.id}_${message.author.id}, Date.now());

Not sure why only part of the code was put in a code block, apologies. Here’s a pastebin to make it easier to read: https://pastebin.com/g8K0uviF

The issue is pretty easy to fix!

This is my code, it worked perfectly fine with me!

if (cooldown !== null && timeout - (Date.now() - cooldown) > 0) {
const time = ms(timeout - (Date.now() - cooldown));
message.channel.send(Sorry you must wait **${time}** before running this command);
} else {

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.