WOKCommands
Search…
Command cooldowns
You can use command cooldowns to ensure your commands are only ran every so often. This is very useful for daily or weekly commands. There are two types of cooldowns in WOKCommands: cooldowns (per user) and global cooldowns (per guild).
Each cooldown type requires a string for it's duration and duration type (seconds, minutes, etc)
Character
Duration
Minimum
Maximum
Example
s
Seconds
1
60
30s
m
Minutes
1
60
10m
h
Hours
1
25
5h
d
Days
1
365
3d
The minimum duration for global cooldowns is 1 minute.
Example of per-user cooldowns:
JavaScript
TypeScript
daily.js
module.exports = {
// Best practice for the built-in help menu
category: 'Economy',
description: 'Gives you daily rewards.',
// Ensure this command can only be ran once every 24 hours
cooldown: '24h',
// Invoked when the command is actually ran
callback: ({}) => {
// TODO: Give the user the rewards
}
}
daily.ts
import { ICommand } from 'wokcommands'
​
export default {
// Best practice for the built-in help menu
category: 'Economy',
description: 'Gives you daily rewards.',
// Ensure this command can only be ran once every 24 hours
cooldown: '24h',
// Invoked when the command is actually ran
callback: ({}) => {
// TODO: Give the user the rewards
}
} as ICommand
Example of per-guild cooldowns:
JavaScript
TypeScript
rewards.js
module.exports = {
// Best practice for the built-in help menu
category: 'Economy',
description: 'Rewards every user who reacts to the message.',
// Ensure this command can only be ran once every 7 days
globalCooldown: '7d',
// Invoked when the command is actually ran
callback: async ({ message, channel }) => {
const { member } = message
const emoji = 'πŸ’°'
const text = `React with ${emoji} to get rewards! Thanks to ${member} for hosting this reward giveaway!`
const newMessage = await channel.send({
content: text
})
newMessage.react(emoji)
// TODO: Listen for reactions to "newMessage"
}
}
rewards.ts
import { ICommand } from 'wokcommands'
​
export default {
// Best practice for the built-in help menu
category: 'Economy',
description: 'Rewards every user who reacts to the message.',
// Ensure this command can only be ran once every 7 days
globalCooldown: '7d',
// Invoked when the command is actually ran
callback: async ({ message, channel }) => {
const { member } = message
const emoji = 'πŸ’°'
const text = `React with ${emoji} to get rewards! Thanks to ${member} for hosting this reward giveaway!`
const newMessage = await channel.send({
content: text
})
newMessage.react(emoji)
// TODO: Listen for reactions to "newMessage"
}
} as ICommand
You should connect WOKCommands to your database if your cooldown or globalCooldown is greater than 5 minutes. See the "DATABASES" section of this documentation for more information. This is because if your bot restarts then cooldown durations held in memory are lost.
Copy link