function updateCommandCooldown(commandName, commandCooldown, userId, cooldowns) {
  // If no cooldown exists for this command, create one
  if (!cooldowns.has(commandName)) {
    cooldowns.set(commandName, new Collection());
  }

  // Get cooldown numbers
  const now = Date.now();
  const timestamps = cooldowns.get(commandName);
  const cooldownAmount = (commandCooldown || defaultCooldown) * 1000;

  // If a cooldown exists for this user
  if (timestamps.has(userId)) {
    // Get command+user cooldown expiration time
    const expirationTime = timestamps.get(userId) + cooldownAmount;

    // Check if cooldown expired
    if (now < expirationTime) {
      // Return remaining cooldown time
      return (expirationTime - now) / 1000;
    }
  }

  // Create a new cooldown for user
  timestamps.set(userId, now);
  setTimeout(() => timestamps.delete(userId), cooldownAmount);

  return 0;
}
/**
 * Check if the command is on cooldown for the specified user.
 * Update cooldowns if command can be used.
 * @param {string} commandName - name of command
 * @param {number} commandCooldown - command cooldown in seconds
 * @param {string} userId - Discord user ID
 * @param {Collection<string, Collection<string, number>>} cooldowns - client command cooldowns
 * @returns {number} number of cooldown seconds remaining
 */
Check if the command is on cooldown for the specified user.
Update cooldowns if command can be used.
Check if the command is on cooldown for the specified user . Update cooldowns if command can be used .
function updateCommandCooldown(commandName, commandCooldown, userId, cooldowns) {
  if (!cooldowns.has(commandName)) {
    cooldowns.set(commandName, new Collection());
  }
  const now = Date.now();
  const timestamps = cooldowns.get(commandName);
  const cooldownAmount = (commandCooldown || defaultCooldown) * 1000;
  if (timestamps.has(userId)) {
    const expirationTime = timestamps.get(userId) + cooldownAmount;
    if (now < expirationTime) {
      return (expirationTime - now) / 1000;
    }
  }
  timestamps.set(userId, now);
  setTimeout(() => timestamps.delete(userId), cooldownAmount);
  return 0;
}
function updateCommandCooldown ( commandName , commandCooldown , userId , cooldowns ) { if ( ! cooldowns . has ( commandName ) ) { cooldowns . set ( commandName , new Collection ( ) ) ; } const now = Date . now ( ) ; const timestamps = cooldowns . get ( commandName ) ; const cooldownAmount = ( commandCooldown || defaultCooldown ) * 1000 ; if ( timestamps . has ( userId ) ) { const expirationTime = timestamps . get ( userId ) + cooldownAmount ; if ( now < expirationTime ) { return ( expirationTime - now ) / 1000 ; } } timestamps . set ( userId , now ) ; setTimeout ( ( ) => timestamps . delete ( userId ) , cooldownAmount ) ; return 0 ; }
Check if the command is on cooldown for the specified user.
Check if the command is on cooldown for the specified user .
// If no cooldown exists for this command, create one // Get cooldown numbers // If a cooldown exists for this user // Get command+user cooldown expiration time // Check if cooldown expired // Return remaining cooldown time // Create a new cooldown for user