Starts with a slash command

Giveaways

A reaction giveaway ends with someone counting emojis at midnight. This one takes entries through a button, one per member, and draws the winner itself when the time is up.

Illustration. The real interface may look different.

How it works

  1. /giveaway-start takes a prize and a duration, posts the giveaway and schedules the draw.

  2. The Enter button counts each member once, however often they click.

  3. When the time is up, the bot picks one entry at random and announces the winner in the same channel.

How to make a giveaway on Discord

The start command books the draw as a scheduled run and keeps its ID, which is what makes cancelling possible. Entries are filed under the ID of the giveaway message, so two giveaways can run side by side.

Describe it to your AI assistant

We just passed 500 members and I want to give away a month of Nitro. Build a giveaway module: /giveaway-start with a prize and a number of minutes, usable by members with Manage Server. Post the giveaway in #giveaways with an Enter button, count each member only once, and when the time is up pick one random winner and announce it in the same channel. Add /giveaway-cancel to call off a running giveaway, and a setting for the minimum number of entries a draw needs.

Copy it and swap in your own channel and role names. Your assistant has a tested version of this example to start from.

Build it in the editor

Four flows: /giveaway-start, the Enter button, the draw and /giveaway-cancel. The draw is a flow the start command books for later, so nothing has to stay running in between.

The 4 flows, step by stepStep names are the ones the editor shows.

Flow 1/giveaway-start

Trigger: Slash command/giveaway-start with the options prize and minutes, limited to members with "Manage server".

  1. Set stored value if (atomic)Claims the host's slot. One host runs one giveaway at a time.
  2. Add to dateWorks out when the draw is due from the minutes option.
  3. Create messageBuilds the giveaway message with the prize and the end time.
  4. Send messagePosts it in the giveaway channel and opens an empty entry list under its ID.
  5. Edit messageAdds the Enter button only now, so nobody can click before the list exists.
  6. Schedule flow runBooks the draw for the end time and stores the ID of that run.

Flow 2Enter

Trigger: Button clickedfrom the Enter button.

  1. Is a value stored?Checks that the giveaway is still open.
  2. Set stored value if (atomic)Claims a marker for this member and this giveaway. A second click gets "you are already in".
  3. Build a shape valueBuilds the entry.
  4. Add item to stored listAdds it to the entry list.

Flow 3The draw

Trigger: Scheduled runthe run booked by /giveaway-start, with the prize, the message ID and the host.

  1. Read a stored valueReads the entry list.
  2. List lengthCompares its length with your minimum. With too few entries the giveaway ends without a winner.
  3. Random item from listPicks one entry at random.
  4. Call another flowRuns the clean-up flow, which deletes the list and the markers and frees the host.
  5. Send messageAnnounces the winner in the giveaway channel.

Flow 4/giveaway-cancel

Trigger: Slash command/giveaway-cancel, with the same permission.

  1. Cancel scheduled flow runCancels the booked draw by its stored ID.
  2. Call another flowRuns the same clean-up flow as the draw.

Test it, change it

What it stores

  • EntriesBy custom keyThe list of everyone who entered, filed under the ID of the giveaway message. Deleted after the draw.
  • Already enteredBy custom keyOne marker per member and giveaway. It decides whether a click counts.
  • Pending drawPer userPer host: the ID of the booked draw and of the giveaway message, kept so the giveaway can be cancelled.

How to test it

  1. Open a flow in the editor and click "Test run". Choose the member under "Run as" and click "Run test". The run uses your real server data but sends, changes and deletes nothing, and shows what each step would have done.
  2. A new flow is a "Draft" and does not run in Discord. Switch it on and click "Save & activate".
  3. In Discord, start a giveaway that runs for one minute, enter with two accounts and click Enter twice with one of them. A minute later the winner is announced and the Enter button no longer accepts entries.
  4. Each real run then shows up under "Executions", with the reason if it failed or was skipped.

What to change

Channel
The giveaway channel is a setting in the module's "Configuration" tab.
Duration
Whoever starts the giveaway sets the minutes, from one minute to two weeks.
Who can start
Change "Required permissions" on the trigger of /giveaway-start.
Wording
The giveaway message is built in /giveaway-start, the winner message in the draw.

Watch out for

  • This build draws one winner. For several winners the draw needs a loop that removes each picked entry from the list.
  • A member who leaves the server after entering can still be drawn. Check the winner before you send the prize.
  • Set "Minimum entries" above 1 if a giveaway with a single entry should not pay out.

Questions about this build

Can a member enter a giveaway more than once?

No. The first click claims a marker for that member and that giveaway. Every later click is answered with a private note that they are already in.

Can I limit a giveaway to one role?

Yes. Add "Member has role" as the first step of the Enter flow and stop with a private reply when the member lacks the role.

What happens if the bot restarts during a giveaway?

The draw is a booked run, and the entries are in storage. Both are still there after a restart, so the winner is drawn at the planned time.

¿Quieres tu servidor en la beta?

V3 es un sistema grande y aún avanza rápido, así que los servidores entran de uno en uno y no todos a la vez. Una persona lee cada solicitud, y te respondemos en unos días.

Los servidores que ya están en la beta deciden buena parte de lo que construimos después. Lo que creas es tuyo: los flows y los módulos se quedan cuando termina la beta.