Collect reward

In this guide, you will learn how to create a one-time use command that allows users to collect a money reward.

1. Create a command

The first step is to create a new command, which you can learn to do in this guide.

2. Set a trigger

Users will collect their reward by using the !collect command, so let's set that up as the trigger:

Trigger

3. Craft the code

Now that we have the initial setup done, it's time to make the command actually work.

We will use:

Prize

The reward that users will receive is 100$ with template economy. Since the template economy uses the money user var to store a user's balance, we will contribute to that var.

Getting user var

Let's get a user's balance and store it in a temporary variable called bal:

$let[bal;$getUserVar[money]]

Calculating new balance

Next, we'll add 100$ to the balance:

$let[bal;$math[$bal+100]]

Saving the new balance

Now that we have the new balance, let's overwrite the current balance with the new one:

$setUserVar[money;$bal]

At this point, the command will successfully increase the balance, but we want to ensure that users can only collect the reward once.

Setting a variable

In order to prevent users from collecting multiple rewards, we need to save information about whether each user has already used the command.

$setUserVar[hasCollected;true]

Adding a condition

Now that we have a variable called hasCollected that returns whether the user has already collected the reward, let's use it to prevent users from collecting the same reward multiple times by putting this code at the beginning of the command:

$onlyIf[$getUserVar[hasCollected]!=true;You cannot collect the same reward more than once!]

Final result

Setup preview

Let's see if it works correctly

Member02/20/2024
!collect
Custom Command Bot 02/20/2024
Enjoy your 100$ reward!
Member02/20/2024
!collect
Custom Command Bot 02/20/2024
You cannot collect the same reward more than once!

Note

You may not always limit executions to one per user, you can use other vars like server vars to restrict the command to one execution per server.

🎉 Congrats!

You've learned how to make a command that can be used only one time!