Variables

Introduction

Variables are how we store data in BDFD. Data can be assigned to users, servers, channels, 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/$getChannelVar.

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. Go to "Variables" tab.

    ex2

  3. Then, click "+ New variable" button.

    ex3

  4. Give the variable a name and value.

    ex4

  5. Finally, save the changes!

    ex5

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. Go to "Variables" tab.

    ex2

  3. Click the edit/pencil icon near the variable name that you want to edit.

    ex3

  4. Provide a new variable name and/or value.

    ex4

  5. Finally, save the changes!

    ex5

Deleting Variables

Here's how you can delete variables:

  1. Select the bot you want to delete the variable for.

  2. Go to "Variables" tab.

    ex2

  3. Select the variable you want to delete.

    ex3

  4. Finally, confirm the deletion!

    ex4

📌 Deleting variables might return error message in those commands which were using the deleted variables.

Global/Global-User Variables

$setVar/$getVar are global variable functions, which means they apply universally (i.e they don't change per-server, per-channel, or per-user).
However, if you provide a user ID in the optional User ID parameter then it becomes a global-user variable.

Global-user variables value stay same with the user in every server. The usage of global-user variables looks like this:

  • $setVar[Variable Name;New Value;User ID]
  • $getVar[Variable Name;User ID]

Global Variables - Functions

  • $setVar[Variable Name;New Value]: Changes the provided global-variable's value to 'New Value'.
  • $getVar[Variable Name]: Gets the current value of the provided global-variable.

📌 Global variables are universal, meaning if the variable gets modified, the modification applies to everyone.

Global Variables - Example

This is the variable we're working with:

ex

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.]

ex

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.]

ex

Global-User Variables - Functions

  • $setVar[Variable Name;New Value;User ID]: Sets the provided variable to 'New Value' for the provided 'User ID'.
  • $getVar[Variable Name;User ID]: Gets the provided variable's value for the given 'User ID'.

📌 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:

ex

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.]

ex

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.]

ex

User Variables

User variables are unique per-user and differ in each server.

User Variables - Functions

  • $setUserVar[Variable Name;New Value;(User ID;Guild ID)]: Sets the provided variable to 'New Value' for the given 'User ID' and 'Guild ID', or the author of the command if no 'User ID' is provided and current guild if no 'Guild ID' is provided.
  • $getUserVar[Variable Name;(User ID;Guild ID)]: Gets the current value for the provided user variable. Returns the author's variable value if no 'User ID' is provided and uses the current guild if no 'Guild ID' is provided.

User Variables - Examples

⚠️ This example would require premium to be fully functional! ⚠️

Here's the variable we're working with:

example

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]!

ex

Server Variables

Server variables are unique per-server.

Server Variables - Functions

  • $setServerVar[Variable Name;New Value;(Server ID)]: Sets the provided variable to 'New Value' for the given 'Server ID', or the server that the command was ran in; if no 'Server ID' was provided.
  • $getServerVar[Variable Name;(Server ID)]: Gets the current value for the provided server variable. Returns the current server's variable value if no 'Server ID' is provided.

Server Variables - Examples

Here's the variable we're working with:

ex

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]]

ex

This command returns how many cookies the server has currently.

$nomention
Total Server Cookies: 🍪 $getServerVar[ServerCookies]

ex

Channel Variables - Functions

  • $setChannelVar[Variable Name;New Value;(Channel ID)]: Sets the provided variable to 'New Value' for the provided 'Channel ID', or the channel that the command was ran in; if no 'Channel ID' was provided.
  • $getChannelVar[Variable Name;(Channel ID)]: Gets the current value for the provided channel variable. Returns the current channel's variable value if no 'Channel ID' is provided.

Channel Variables - Examples

Here's the variable we're working with:

ex

This command adds 1 uses to the 'Uses' variable value, everytime it is ran.

📌 The trigger for this command will be your bot's prefix, example: !.

$nomention
This channel has now `$sum[$getChannelVar[Uses];1]` uses of the command.
$setChannelVar[Uses;$sum[$getChannelVar[Uses];1]]

ex

This command returns how many command uses the channel has currently.

$nomention
Command used `$getChannelVar[Uses]` times in this channel

ex

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;11], $random[100;1001], 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;11], $random[100;1001], 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.