# Flows

> A flow is one trigger followed by connected steps. Learn the seven kinds of flow and how steps connect.

Source: https://docs.buildcord.dev/concepts/flows/

A *flow* is the unit of logic in a bot. It starts with one trigger, then continues through *nodes* (steps) that you connect with wires.

## Kinds of flow

The kind of a flow decides what starts it. You choose the kind when you create the flow, and the trigger node on the canvas follows from it.

| Kind | Starts when | Needs the gateway |
| --- | --- | --- |
| Command | Someone uses the slash command. | No |
| Right-click command | Someone picks it from the Apps menu of a member or a message. | No |
| Event | Something happens in a server, such as a member joining. | Yes |
| Schedule | A timer fires, using a cron expression. | No |
| Button action | Someone presses a button, or picks from a menu, that names the action. | No |
| Sub-flow | Another flow runs it. It never starts by itself. | No |
| Webhook | An outside service calls its address. | No |

See [Triggers](https://docs.buildcord.dev/nodes/triggers) for each one in detail.

> **Note: Commands-only and gateway bots**
>
> A bot that only answers slash commands, button presses, webhooks and schedules stays off the Discord gateway. A bot that reacts to server events, uses voice, changes its status, waits for replies, or runs your own code needs a gateway connection, which the paid plan includes. See [Plans](https://docs.buildcord.dev/concepts/plans).

## Wires and ways out

Every node has one or more *ways out*, shown as handles on its right edge. You draw a wire from a way out to the next node. Most nodes have a single way out. Nodes that branch have several, and each is labeled.

- A wire that leads nowhere ends the path. The run finishes, or, inside a loop, control returns to the loop for its next pass.
- A node that has failed can lead somewhere else if you turn on **If it fails**. Without that, a failure stops the run and the error is logged. See [Handling failures](#handling-failures).

## Runs

Each time a flow starts, it creates a *run*. A run carries its own values, such as who triggered it and what the command's options were. Many runs of the same flow can happen at once.

Some nodes pause a run: [Message with buttons or a menu](https://docs.buildcord.dev/nodes/messages/message-with-buttons), [Send a form](https://docs.buildcord.dev/nodes/messages/send-form), [Wait](https://docs.buildcord.dev/nodes/flow-control/wait) and [Wait for a reply](https://docs.buildcord.dev/nodes/flow-control/wait-for-reply). A paused run is saved and takes no memory. It can wake minutes or days later, after restarts and deploys, and finishes on the version of the bot it started on.

> **Warning: Buttons without an action expire**
>
> A button that has no action only continues the run that sent it, and only for a day. Give the button an action when it needs to work for as long as its message exists. See [Designs](https://docs.buildcord.dev/concepts/designs).

## Handling failures

Most nodes can talk to Discord, a database or an outside service, so they can fail. To catch a failure, open the node's settings and turn on **If it fails**. The node gains a red way out that you can wire to a recovery path, such as a reply that explains what went wrong.

Nodes that only work on values the run already holds can't fail, so they don't offer this: comparisons, permission checks, chance, user checks, cooldowns, unique variables, text manipulation, loops, loop breaks and stop.

The runtime retries on its own only for rate limits and connections that never opened.

## Versions

Deploying creates an immutable, versioned [blueprint](https://docs.buildcord.dev/reference/blueprint). A run records the version it started on and finishes on it, including runs that pause for days. Editing a flow never changes a run that's already underway.
