nocli-handler.js
  • ๐Ÿ”—Links
    • Link to NPM Package
    • Link to Github Package
  • ๐Ÿš€Introduction
    • Welcome
    • Changelog
  • ๐ŸงชGetting Started
    • Setting Up Your Project
  • โ“Guides
    • Instance
      • Providing a MongoDB Connection
      • Things you really need to know
    • Commands
      • Creating a simple "Ping Pong" Command
      • Command Arguments
      • Enabling Slash Commands
      • Deleting a Command
      • Guild and Owner-only Commands
      • Command Aliases
      • Deferring a command reply
      • Running Events inside a Command
      • Command Cooldowns
      • Setting up Autocomplete
      • Required Permissions
  • ๐ŸซClasses
    • NoCliHandler
      • .connectToMongoDB()
    • ChannelCommands
      • .action()
      • .add()
      • .remove()
      • .getAvailableChannels()
    • Command
    • CommandHandler
      • .getValidations()
      • .readFiles()
      • .runCommand()
      • .isCommand()
    • CustomCommands
      • .loadCommands()
      • .create()
      • .delete()
      • .run()
    • DisabledCommands
      • .loadDisabledCommands()
      • .disable()
      • .enable()
      • .isDisabled()
    • PrefixHandler
      • .loadPrefixes()
      • .get()
      • .set()
    • SlashCommands
      • .getCommands()
      • .findCommand()
      • .optionsAreDifferent()
      • .create()
      • .delete()
      • .createOptions()
    • EventHandler
      • .readFiles()
      • .registerEvents()
      • .isEvent()
  • ๐Ÿ› ๏ธUtilities
    • Cooldowns
      • .loadCooldowns()
      • .getKeyFromCooldownUsage()
      • .cancelCooldown()
      • .updateCooldown()
      • .verifyCooldown()
      • .getKey()
      • .canBypass()
      • .start()
      • .canRunAction()
    • handleCommandAutocomplete
    • handleError
    • log
    • getAllFiles
    • importFile
  • ๐Ÿ†ŽDefinitions
    • NoCliCategoryConfiguration
    • NoCliCategoryType
    • ICommand
    • CommandOptions
    • CommandCallbackOptions
    • NoCliCommandCooldown
    • NoCliCommandType
    • cooldownTypesArray
    • NoCliCooldownType
    • NoCliCooldownKeyOptions
    • IEvent
    • EventConfigurationOptions
    • DynamicValidationConfigurationOptions
    • DynamicValidationCheck
    • DynamicValidationCheckFunction
    • NoCliHandlerOptions
    • NoCliCooldownOptions
    • NoCliCooldownConfigOptions
    • MongoDBConnection
    • MongoDBResult
    • DebugOptions
    • ConfigOptions
    • ValidationPluginsOption
    • NoCliEmojiConfigOptions
    • NoCliLanguageType
    • NoCliRuntimeValidationType
    • NoCliSyntaxValidationType
Powered by GitBook
On this page
  • How does cooldowns work?
  • What does these types of cooldowns help in?
  • updateCooldown() and cancelCooldown() functions
  1. Guides
  2. Commands

Command Cooldowns

Commands should have a cooldown to reduce the number of times a user uses a command to prevent an issue called "Spamming".

How does cooldowns work?

cooldowns is an Object option that has 4 types of command cooldowns: perUser, perGuild, perUserPerGuild and global. These types of cooldowns help control servers that use a command and prevent abusing it which may crash the bot.

Let's use the "ping" command to demonstrate this:

ping.js
/**
 * @type {import("nocli-handler.js").ICommand}
 */
const Command = {
    description: "Checks client latency",
    type: "BOTH",
    cooldowns: {
        // Set a command cooldown type listed in the documentation
    }
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
}

module.exports = Command;
ping.ts
import { ICommand } from "nocli-handler.js";

export default {
    description: "Checks client latency",
    type: "BOTH",
    cooldowns: {
        // Set a command cooldown type listed in the documentation
    }
    callback: ({ client, message, args, text }) => {
        return `๐Ÿ“ Pong! \`${client.ws.ping}ms\``;
    }
} as ICommand;

What does these types of cooldowns help in?

Here is a table and a specific description on how cooldown types work:

Cooldown Type
Description

perUser

Sets a cooldown for each user, even if they are in another server or not

perGuild

Sets a cooldown for each server. When a user runs a command in a server, other users will be affected when running that command. However, other servers will not be affected.

perUserPerGuild

Sets a cooldown for each user. Other users will not be affected. However, the user can still run that command in another server.

global

Sets a whole cooldown for all users when a user runs this command. This means that even if other users are not in the same server, the cooldown will still affect them.

When specifying cooldowns, please only specify one of them. Multiple cooldowns detected will result in a NoCliCommandError.

Also, bot developers should have the freedom to manage cooldowns the way they want. This is useful when you want to slow down the usage of a command by a user. This is why updateCooldown() and cancelCooldown() options are implemented into ICommand.callback()

updateCooldown() and cancelCooldown() functions

updateCooldown() updates the time the cooldown ends for the user while cancelCooldown() cancels the whole cooldown for the user.

updateCooldown() and cancelCooldown()functions can only be used when a command is executed.

PreviousRunning Events inside a CommandNextSetting up Autocomplete

Last updated 2 years ago

โ“