|
1 | 1 | # $channelCooldown |
2 | 2 |
|
3 | | -Sets a cooldown for a command, *per channel*! This means the command can only be used again in the specific channel after the specified cooldown has expired. |
| 3 | +Sets a cooldown for a command in channel. |
4 | 4 |
|
5 | | -#### Usage: |
| 5 | +## Usage |
6 | 6 |
|
7 | | -`$channelCooldown[time (default is 5s);Error message]` |
| 7 | +```bash |
| 8 | +$channelCooldown[time;error message] |
| 9 | +``` |
| 10 | +1. **time** - (Optional) default value: `5s`. The cooldown duration. Example times: `10s`, `1m`, `2h`, `1d` |
| 11 | +2. **error message** - (Optional) default value: (none). The message to send if a cooldown is still in progress. |
8 | 12 |
|
9 | | -* **time:** The cooldown duration. Defaults to 5 seconds if not provided. Examples: `10s`, `1m`, `2h`, `1d`. |
10 | | -* **Error message:** The message to send when a user tries to use the command before the cooldown expires. |
| 13 | +## Example |
11 | 14 |
|
12 | | -### Example: |
| 15 | +#### Using $channelCooldown |
| 16 | + |
| 17 | +As you can see, first time it will set the cooldown and execute code below, second time, it won't allow execution |
13 | 18 |
|
14 | 19 | <discord-messages> |
15 | | - <discord-message :bot="false" role-color="#ffcc9a" author="Member"> |
16 | | - !!exec $channelCooldown[2h;You can get points again after %time%]<br> |
17 | | - $sendMessage[You received 100x points.] |
18 | | - </discord-message> |
19 | | - <discord-message :bot="true" role-color="#0099ff" author="Custom Command" avatar="https://media.discordapp.net/avatars/725721249652670555/781224f90c3b841ba5b40678e032f74a.webp"> |
20 | | - You can get points again after 1 hour 54 minutes and 56 seconds |
21 | | - </discord-message> |
| 20 | + <discord-message :bot="false" role-color="#d6e0ff" author="User" avatar="https://cdn.discordapp.com/embed/avatars/0.png"> |
| 21 | + !!exec $channelCooldown[5m;You're on cooldown!]<br> |
| 22 | + You're not on cooldown! |
| 23 | + </discord-message> |
| 24 | + <discord-message :bot="true" role-color="#5fb0fa" author="Custom Command" avatar="https://doc.ccommandbot.com/bot-profile.png"> |
| 25 | + You're not on cooldown! |
| 26 | + </discord-message> |
| 27 | + <discord-message :bot="false" role-color="#d6e0ff" author="User" avatar="https://cdn.discordapp.com/embed/avatars/0.png"> |
| 28 | + !!exec $channelCooldown[5m;You're on cooldown! Still %mins%m remaining!]<br> |
| 29 | + You're not on cooldown! |
| 30 | + </discord-message> |
| 31 | + <discord-message :bot="true" role-color="#5fb0fa" author="Custom Command" avatar="https://doc.ccommandbot.com/bot-profile.png"> |
| 32 | + You're on cooldown! Still 4m remaining! |
| 33 | + </discord-message> |
22 | 34 | </discord-messages> |
23 | 35 |
|
24 | | -In this example, the command will give the user 100 points. If they try to use the command again within 2 hours in the same channel, they will receive the error message: "You can get points again after [remaining time]". |
25 | | - |
26 | | -## Usable Macros in Error Message: |
| 36 | +## Placeholders |
27 | 37 |
|
28 | | -These macros can be used in your error message to provide dynamic information about the cooldown. |
| 38 | +Available placeholders you can use in error message |
29 | 39 |
|
30 | | -| Macro | Description | Output Example | |
31 | | -| ------------ | ------------------------------------------------- | ---------------------------------------- | |
32 | | -| `%time%` | Replaced with the remaining time in a readable format. | `5 days 1 hour 54 minutes and 56 seconds` | |
33 | | -| `%days%` | The number of days remaining. | `5` | |
34 | | -| `%hrs%` | The number of hours remaining. | `1` | |
35 | | -| `%mins%` | The number of minutes remaining. | `54` | |
36 | | -| `%secs%` | The number of seconds remaining. | `56` | |
37 | | -| `%timestamp%` | Unix timestamp (seconds) for when the cooldown expires. | `1680711176` | |
38 | | -| `%relative%` | Displays the remaining time using Discord's relative timestamp feature (updates automatically). |  | |
| 40 | +| Placeholder | Description | Output Example | |
| 41 | +| ------------- | --------------------------------------------------------- | ----------------------------------------- | |
| 42 | +| `%time%` | The full time remaining | `1 day 2 hours 3 minutes and 4 seconds` | |
| 43 | +| `%days%` | The number of days remaining | `1` | |
| 44 | +| `%hrs%` | The number of hours remaining | `2` | |
| 45 | +| `%mins%` | The number of minutes remaining | `3` | |
| 46 | +| `%secs%` | The number of seconds remaining | `4` | |
| 47 | +| `%timestamp%` | Timestamp of cooldown expiration in seconds | `1735689600` | |
| 48 | +| `%relative%` | Shows Discord relative timestamp (Automatically Updates) | `<t:1735689600:R>` - Displays: `in 1 day` | |
39 | 49 |
|
40 | | -::: tip Note |
41 | | -You can send styled messages or embeds by using the [Message Curl Format](../CodeReferences/ref.message_curl_format.md) in the error message. |
| 50 | +::: warning Warning |
| 51 | +Place this function above the code you want to use cooldown for. All code before this function will be executed. |
42 | 52 | ::: |
43 | | - |
44 | | -::: tip Related Functions |
45 | | -* [$cooldown](../Cooldown/cooldown.md): Sets a cooldown for a command, *per user*. |
46 | | -* [$serverCooldown](../Cooldown/serverCooldown.md): Sets a cooldown for a command, *per server*. |
| 53 | +::: tip Suggestion |
| 54 | +You can send embeds, select menus and buttons by using the [message curl format](../CodeReferences/ref.message_curl_format.md). |
47 | 55 | ::: |
48 | 56 |
|
49 | | -::: danger Important |
50 | | -Place the `$channelCooldown` function on the **FIRST line** of your command's code. If it's not the first line, the code before it will execute regardless of the cooldown, and the cooldown won't apply correctly. |
51 | | -::: |
52 | 57 |
|
53 | | -##### Function Difficulty: <Badge type="tip" text="Easy" vertical="middle" /> |
| 58 | +##### Related functions: [$cooldown](../Cooldown/cooldown.md) [$serverCooldown](../Cooldown/serverCooldown.md) |
54 | 59 |
|
55 | | -###### Tags: <Badge type="tip" text="Cooldown" vertical="middle" /> <Badge type="tip" text="Channel Cooldown" vertical="middle" /> <Badge type="tip" text="Raid Limit" vertical="middle" /> <Badge type="tip" text="Raid Limited" vertical="middle" /> |
| 60 | +##### Function Difficulty: <Badge type="tip" text="Easy" vertical="middle" /> |
| 61 | +###### Tags: <Badge type="tip" text="Cooldown" vertical="middle" /> <Badge type="tip" text="Channel Cooldown" vertical="middle" /> <Badge type="tip" text="Limit" vertical="middle" /> |
0 commit comments