Variables Guide
Introduction
Variables are how we store data in BDFD. Data can be assigned to users, servers, and globally. Each variable has two elements, which we will breakdown in this section.
Variable Elements
name
- The name of the variable. This can't be modified by the bot, its used to "call" the current variable.value
- The value of the variable. This can be modified by the bot, its returned when the variable name is called in$getVar
/$getUserVar
/$getServerVar
.
Creating Variables
Creating variables can only be done in the app. Here's how to create a variable, which you can get and modify later.
#1: Select the bot you want to add the new variable to.
#2: Select the "Variables" tab.
#3: Create a new variable.
#4: Give the variable a name and value.
#5: Save your changes!
Editing Variables
Here's how you can modify an existing variable's name/default value.
#1: Select the bot you want to edit the variable for.
#2: Select the "Variables" tab.
#4: Select the variable you want to edit.
#5: Edit the variable name and/or value.
#6: Save your changes!
Deleting Variables
Here's how you can delete variables,
#1: Select the bot you want to delete the variable for.
#2: Select the "Variables" tab.
#4: Select the variable you want to delete.
#5: Confirm the deletion!
⚠️ Deleting variables might return error message in those commands which were using the deleted variables.
Global/Global-User Variables
$setVar[variableName;newValue]
/$getVar[variableName]
are global variable functions, this means they apply to universally (they don't change per-server or per-user). However, if you input a user in the optional userID
field then it becomes a global-user variable. Global-user variables stay with the user in every server. The usage of global-user variables looks like this: $setVar[variableName;newValue;userID]
/$getVar[variable name;userID]
.
Global Variables - Functions
$setVar[variableName;newValue]
- Changes the provided global-variable's value to 'newValue'.
🧙♂️ Global variables are universal, meaning if the variable gets modified, the modification applies to everyone.
$getVar[variableName]
- Gets the current value of the provided global-variable.
Global Variables - Example
This is the variable we're working with:
This command adds 1
cool point to the 'CoolCount' variable value, everytime it is ran.
$nomention
$setVar[CoolCount;$sum[$getVar[CoolCount];1]]
Cool counter updated! 😎
$c[Updates the variable for all servers.]
This command returns how many cool points have been earned.
$nomention
Cool counter is at $getVar[CoolCount] currently! Keep running `!cool` for more cool points.
$c[This is the same for everyone, no matter who runs it.]
Global-User Variables - Functions
$setVar[variableName;newValue;userID]
- Sets the provided variable to 'newValue' for the inputted 'userID'.$getVar[variableName;userID]
- Gets the provided variable's value for the inputted 'userID'.
🧙♂️ Global-user variables stay with the user in every server. Unlike user variables which are unique per-user and differ in each server.
Global-User Variables - Examples
This is the variable we're working with:
This command modifies the user's bio.
$nomention
$argsCheck[>1;❌ Please provide text!]
$setVar[Bio;$noMentionMessage;$authorID]
Successfully updated your bio!
$c[Updates the variable for the user in all servers.]
This command returns the user's current bio.
$nomention
**<@$mentioned[1;yes]>'s Bio:**
$getVar[Bio;$mentioned[1;yes]]
$c[Gets the author/mentioned-user's current bio.]
User Variables
User variables are unique per-user and differ in each server.
User Variables - Functions
$setUserVar[variableName;newValue;(userID;guildID)]
- Sets the provided variable to 'newValue' for the inputted 'userID' and 'guildID', or the author of the command if no 'userID' is provided and current guild if no 'guildID' is provided.$getUserVar[variableName;(userID;guildID)]
- Gets the current value for the provided user variable. Returns the author's variable value if no 'userID' is provided and uses the current guild if no 'guildID' is provided.
User Variables - Examples
⚠️ This example would require premium to be fully functional! ⚠️
Here's the variable we're working with:
This command adds 1
to the user's 'Mentions' variable, everytime the user mentions someone.
🧙♂️ The trigger for this command would be
$messageContains[<@]
.
$nomention
$setUserVar[Mentions;$sum[$getUserVar[Mentions];1]]
This command returns how many times the user has mentioned others, in the current server:
$nomention
You have mentioned others `$getUserVar[Mentions]` times in $serverName[$guildID]!
Server Variables
Server variables are unique per-server.
Server Variables - Functions
$setServerVar[variableName;newValue;(optional) serverID]
- Sets the provided variable to 'newValue' for the inputted 'serverID', or the server that the command was ran in; if no 'serverID' was provided.$getServerVar[variableName;(optional) serverID]
- Gets the current value for the provided server variable. Returns the current server's variable value if no 'serverID' is provided.
Server Variables - Examples
Here's the variable we're working with:
This command adds 1
cookie to the 'ServerCookies' variable value, everytime it is ran.
$nomention
This server now has `$sum[$getServerVar[ServerCookies];1]` cookies picked 🍪
$setServerVar[ServerCookies;$sum[$getServerVar[ServerCookies];1]]
This command returns how many cookies the server has currently.
$nomention
Total Server Cookies: 🍪 $getServerVar[ServerCookies]
Economy
Local vs Global
- Local Economy - Changes per server. If a user has 10,000 coins in one server, in another server they would have a different amount. For example, Unbelievaboat has a local economy. (local economy uses user-variables)
- Global Economy - Does not change per server. If a user has 10,000 coins in one server, in another server they would have the same amount. For example, Dank Memer has a global economy. (global economy uses global-user variables)
Local Economy
- Replace "Money" with your cash/money variable, if "Money" is the name of your money variable then you can just leave it as is!
- Replace "Amount" with the amount of money you want to add/remove to/from the user. Like this:
100
,$random[1;10]
,$random[100;1000]
,10000
.
Gets the user's current balance. If a user mention is provided, then the bot will return that user's balance:
$getUserVar[Money;$mentioned[1;yes]]
Adds money to the mentioned user:
$setUserVar[Money;$sum[Amount;$getUserVar[Money;$mentioned[1]]];$mentioned[1]]
Adds money to the user running the command:
$setUserVar[Money;$sum[Amount;$getUserVar[Money]]]
Removes money to the mentioned user:
$setUserVar[Money;$sub[Amount;$getUserVar[Money;$mentioned[1]]];$mentioned[1]]
Removes money from the user running the command:
$setUserVar[Money;$sub[Amount;$getUserVar[Money]]]
Leaderboard:
$userLeaderboard[Money;asc]
Global Economy
- Replace "Money" with your cash/money variable, if "Money" is the name of your money variable then you can just leave it as is!
- Replace "Amount" with the amount of money you want to add/remove to/from the user. Like this:
100
,$random[1;10]
,$random[100;1000]
,10000
.
Gets the user's current balance/amount of money. If a user mention is provided then the bot will return that user's balance:
$getVar[Money;$mentioned[1;yes]]
Adds money to the mentioned user:
$setVar[Money;$sum[Amount;$getVar[Money;$mentioned[1]]];$mentioned[1]]
Adds money to the user running the command:
$setVar[Money;$sum[Amount;$getVar[Money;$authorID]];$authorID]
Removes money to the mentioned user:
$setVar[Money;$sub[Amount;$getVar[Money;$mentioned[1]]];$mentioned[1]]
Removes money from the user running the command:
$setVar[Money;$sub[Amount;$getVar[Money;$authorID]];$authorID]
Global leaderboard:
$globalUserLeaderboard[Money;asc]
Leaderboards
You can generate variable leaderboards, using the functions below. Click the hyperlinks for more information about these leaderboard functions.
- $globalUserLeaderboard - Global-User Variables.
- $userLeaderboard - User Variables.
- $serverLeaderboard - Server Variables.
- $getLeaderboardValue - Fetchs leaderboard value.
Additional Tips
- You can change the variables with a
userID
or with a mention of the user. Here's a example:
$setUserVar[Money;0;<@696368083517964288>]
$setUserVar[Money;0;696368083517964288]
$getUserVar[Money;<@696368083517964288>]
$getUserVar[Money;696368083517964288]
$setVar[Money;0;<@696368083517964288>]
$setVar[Money;0;696368083517964288]
$getVar[Money;696368083517964288]
$getVar[Money;696368083517964288]
$c[All of these would work fine!]