Skip to main content

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

A Collection is a list. See Lists and objects.

/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:
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:
5

Clear the list

Save a value: entries, Collection Operation Clear collection.
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.

Try it

  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.
  • Show everyone who entered: {DBVAR_entries.length} people.