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
1
module.exports = {
2
// Best practice for the built-in help menu
3
category: 'Economy',
4
description: 'Gives you daily rewards.',
5
6
// Ensure this command can only be ran once every 24 hours
7
cooldown: '24h',
8
9
// Invoked when the command is actually ran
10
callback: ({}) => {
11
// TODO: Give the user the rewards
12
}
13
}
Copied!
daily.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
// Best practice for the built-in help menu
5
category: 'Economy',
6
description: 'Gives you daily rewards.',
7
8
// Ensure this command can only be ran once every 24 hours
9
cooldown: '24h',
10
11
// Invoked when the command is actually ran
12
callback: ({}) => {
13
// TODO: Give the user the rewards
14
}
15
} as ICommand
Copied!
Example of per-guild cooldowns:
JavaScript
TypeScript
rewards.js
1
module.exports = {
2
// Best practice for the built-in help menu
3
category: 'Economy',
4
description: 'Rewards every user who reacts to the message.',
5
6
// Ensure this command can only be ran once every 7 days
7
globalCooldown: '7d',
8
9
// Invoked when the command is actually ran
10
callback: async ({ message, channel }) => {
11
const { member } = message
12
13
const emoji = '💰'
14
const text = `React with ${emoji} to get rewards! Thanks to ${member} for hosting this reward giveaway!`
15
16
const newMessage = await channel.send({
17
content: text
18
})
19
newMessage.react(emoji)
20
21
// TODO: Listen for reactions to "newMessage"
22
}
23
}
Copied!
rewards.ts
1
import { ICommand } from 'wokcommands'
2
3
export default {
4
// Best practice for the built-in help menu
5
category: 'Economy',
6
description: 'Rewards every user who reacts to the message.',
7
8
// Ensure this command can only be ran once every 7 days
9
globalCooldown: '7d',
10
11
// Invoked when the command is actually ran
12
callback: async ({ message, channel }) => {
13
const { member } = message
14
15
const emoji = '💰'
16
const text = `React with ${emoji} to get rewards! Thanks to ${member} for hosting this reward giveaway!`
17
18
const newMessage = await channel.send({
19
content: text
20
})
21
newMessage.react(emoji)
22
23
// TODO: Listen for reactions to "newMessage"
24
}
25
} as ICommand
Copied!
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