> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dogebot.net/llms.txt
> Use this file to discover all available pages before exploring further.

# Giveaways

> An Enter button, a list of entries and a random winner.

> **What you'll build**
>
> * `/giveaway-start prize`: staff post a giveaway with an **Enter** button.
> * Members press **Enter**. Each person can only enter once.
> * `/giveaway-end`: staff pick a random winner.

## The variables to make

| Name | Type | Where it's kept | Starting value | What it's for |
| - | - | - | - | - |
| `entries` | **Collection** | Server Specific | empty | The user IDs of everyone who entered |
| `prize` | **Text** | Server Specific | empty | What the winner gets |

A Collection is a list. See [Lists and objects](/variables/lists-objects-and-members).

## /giveaway-start

**1. Make the command and input**

A **Slash command** called `giveaway-start`. Add a **Text** input called `prize`. Make it required.

**2. Staff only**

Add the check that looks at **permissions** (search `permission`): **Manage Server**. Under its **Else** block: **Reply** `Only staff can start a giveaway.`

**3. Start fresh: straight under the check**

1. **Save a value**: `entries`, Collection Operation **Clear collection**.
2. **Save a value**: `prize`, Value `{option_prize}`.

**4. Post the giveaway**

Add a message block with a **button** (search `button`). Write:

```text theme={null}
GIVEAWAY!
Prize: {DBVAR_prize}
Press Enter to join.
```

Add one green button called **Enter**.

## What Enter does

Under the **Enter** button:

**1. Already in?**

Add **Compare**: is `{DBVAR_entries.has[{user_id}]}` equal to `true`? Straight under it: **Reply** privately `You already entered. Good luck!`

**2. Add them: under the Else block**

1. **Save a value**: `entries`, Collection Operation **Push value to end**, Value `{user_id}`.
2. **Reply** privately: `You're in! {DBVAR_entries.length} people have entered.`

## /giveaway-end

**1. Make the command**

A **Slash command** called `giveaway-end`, with the same **permissions** check as before.

**2. Anyone in?**

Straight under the permissions check, add **Compare**: `{DBVAR_entries.length}` `Less Than` `1`. Straight under it: **Reply** `Nobody entered.`

**3. Pick the winner: under the Else block**

Add a **Temporary value** block called `winner` with the value `{DBVAR_entries.random}`. This picks one person and keeps them for the rest of the run.

**4. Announce it**

**Reply**:

```text theme={null}
The winner of {DBVAR_prize} is {user_name[{winner}]}! Congratulations!
{DBVAR_entries.length} people entered.
```

**5. Clear the list**

**Save a value**: `entries`, Collection Operation **Clear collection**.

> [!NOTE]
>
> Why the **Temporary value**? `{DBVAR_entries.random}` picks a random entry. Saving the pick once as `{winner}` makes sure the same winner is used everywhere after it. See [Short-lived values](/variables/short-lived-values).

## Try it

> [!TIP]
>
> 1. Type `/giveaway-start` with the prize `Nitro`.
> 2. Press **Enter** on two accounts. Press it again: the bot says you already entered.
> 3. Type `/giveaway-end`. The bot names a winner.
> 4. On the **Database** page, press **Stored values** on `entries`. It is empty again.

## Make it yours

* Show when it ends: add `Ends <t:{time_ahead_unix_h_24}:R>` to the giveaway message.
* End it by itself: run the `/giveaway-end` blocks from a timed event. See [Scheduled messages](/build-real-systems/scheduled-messages).
* Show everyone who entered: `{DBVAR_entries.length}` people.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.