Sign up
Login
New paste
Home
Trending
Archive
English
English
Português
Sign up
Login
New Paste
Browse
const { MessageEmbed, Collection } = require("discord.js"); const Discord = require("discord.js") /** * * @param {*} message A DiscordMessage, with the client, information * @param {*} command The Command with the command.name * @returns BOOLEAN */ module.exports.onCoolDown = onCoolDown; function onCoolDown(message, cmd) { if(!message || !message.client) throw "No Message with a valid DiscordClient granted as First Parameter"; if(!cmd || !cmd.name) throw "No Command with a valid Name granted as Second Parameter"; const client = message.client; if (!client.cooldowns.has(cmd.name)) { //if its not in the cooldown, set it too there client.cooldowns.set(cmd.name, new Collection()); } const now = Date.now(); //get the current time const timestamps = client.cooldowns.get(cmd.name); //get the timestamp of the last used commands const cooldownAmount = (cmd.cooldown || settings.default_cooldown_in_sec) * 1000; //get the cooldownamount of the command, if there is no cooldown there will be automatically 1 sec cooldown, so you cannot spam it^^ if (timestamps.has(message.member.id)) { //if the user is on cooldown const expirationTime = timestamps.get(message.member.id) + cooldownAmount; //get the amount of time the user needs to wait until he can run the cmd again if (now < expirationTime) { //if the user is still on cooldonw const timeLeft = (expirationTime - now) / 1000; //get the lefttime //return true return timeLeft } else { //if user is not on cooldown, set it to the cooldown timestamps.set(message.member.id, now); //set a timeout function with the cooldown, so it gets deleted later on again setTimeout(() => timestamps.delete(message.member.id), cooldownAmount); //return false aka not on cooldown return false; } } else { //if user is not on cooldown, set it to the cooldown timestamps.set(message.member.id, now); //set a timeout function with the cooldown, so it gets deleted later on again setTimeout(() => timestamps.delete(message.member.id), cooldownAmount); //return false aka not on cooldown return false; } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Português
Do you like cookies?
🍪 We use cookies to ensure you get the best experience on our website.
Learn more
I agree