# Cooldown

> Let the rest of the flow run once per key for a set time. While the key is on cooldown, the blocks inside run instead and the flow stops.

- ID: `cooldown`
- Type: Block
- Category: [Logic](https://inventor.bot/docs/reference/blocks/logic.md)

> Use a key like the user's ID for a per-user cooldown. Duration is like 30s, 10m or 1d. "This Flow" keeps the cooldown to this flow, "Global" shares it with every flow using the same key. In a custom block, "This Flow" means the flow that called it.

**Inputs**

| Name | Required | Description | Value |
| --- | --- | --- | --- |
| `key` | yes | What the cooldown is for, like a user ID. | e.g. `"[[ trigger.user_id ]]"` |
| `duration` | yes | How long the cooldown lasts (30s, 10m, 1d). | e.g. `"1m"` |
| `scope` |  | Whether the cooldown is for this flow only, or shared by every flow. | `"This Flow"`, `"Global"` |
| `on_cooldown` |  | While On Cooldown | blocks: `func() { ... }` |

**Outputs**

| Name | Description | Value |
| --- | --- | --- |
| `seconds_left` | Seconds until the cooldown ends. | e.g. `"42"` |
| `ends_at` | When the cooldown ends. | e.g. `"1700003600"` |

**Example**

```go
// cooldown
cooldown2 := cooldown(Args{key: "[[ trigger.user_id ]]", duration: "1m"})
send_text_message(Args{
	channel_id:      trigger.channel_id,
	message_content: "Seconds Left: " + cooldown2.seconds_left,
})
```