Variables
Last updated
Was this helpful?
Last updated
Was this helpful?
Variables allow you to store data from API requests, action outputs, custom data and more. Variables can be used in almost every field of the actions and conditions .
The available variables in your command-builder or event-builder may vary depending on the action, custom variables you have, API requests you use, and the event you might be using in case you are using the event builder. Here you may find some general information on what they are and how to use them.
You can add a target to your variable to get data of a specific user, channel, role or server (more targeting options are available when using Object Variables). To do so, add square brackets []
at the very end of your variable*. Make sure to add a valid ID, variable or option. See below for more info.
* Targeting is slightly different for : the square brackets go before the first dot. For example, {Channel[ID].name}
instead of {Channel.name[ID]}
.
You can use a plain ID as a target. This means the variable will always return the value of the same user, channel or role.
Below are some examples:
{user_icon[136327647792726016]}
{user_joinedAt[136327647792726016]}
{channel_name[1021852614725480448]}
In custom commands you can use an option for your target (make sure it's a valid variable type: you need to use user options if you want to target a user using a option). The variable name should be inside your square brackets []
, without any curly brackets {}
around it, and preceded by option_
.
Below are some examples:
{user_icon[option_user]}
{user_joinedAt[option_player]}
{channel_name[option_channel]}
Lastly, you can also use other variables that contain an ID. Unlike options, make sure to paste the full variable inside your square brackets []
, including the curly brackets {}
.
Below are some examples:
{user_icon[{bot_id}]}
{user_joinedAt[{api.response.id}]}
{channel_name[{BGVAR_my_custom_variable}]}
You can also store data only in a specific command / event execution, meaning that once the execution of the command / event is completed, saved data will be deleted. This is useful to easily store temporary data. Check out the Set a unique variable page to learn more.
Some variables in BotGhost allow you to access properties of a larger object through dot notation. These variables start with a Capital letter and give you access to all the properties available on their respective Discord.js objects. Currently these objects are available:
{Guild}
{Channel}
{Member}
{User}
{Role}
{Invite}
The guild variable gives you access to the properties of the guild (server) a command was used in or an event was triggered in. You can also access a specific guild by enclosing a guild ID in square brackets ({Guild[822426820447567872].name}
).
For example:
{Guild.name}
{Guild[822426820447567872].name}
{Guild.roles}
{Guild.bans}
{Guild.icon}
The channel variable gives you access to the properties of the channel a command was used in or an event was triggered in. You can also access a specific channel by enclosing a channel ID in square brackets ({Channel[1111802548312096778].name}
).
For events this will be the channel associated with the event. For voice events this will be a voice channel.
For example:
{Channel.name}
{Channel[1111802548312096778].name}
{Channel.type}
{Channel.id}
{Channel.position}
The member variable gives you access to the properties of the guild member who used a command or triggered an event. You can also access a specific member by enclosing a member ID in square brackets ({Member[136327647792726016].avatar}
).
For example:
{Member.user.username}
{Member[136327647792726016].user.username}
{Member.avatar}
{Member.roles}
{Member.presence}
The user variable gives you access to the properties of the user who used a command or triggered an event. You can also access a specific user by enclosing a user ID in square brackets ({User[136327647792726016].avatar}
).
For example:
{User.username}
{User.globalName}
{User.avatar}
{User.banner}
The role variable gives you access to the properties of a specific role, that can be either provided by a role ID or a role option. To access the object, enclosing a role ID in square brackets ({Role[905462520519745537].color}
).
For example:
{Role[905462520519745537].icon}
{Role[option_role].name}
{Role[{event_role_id}].hoist}
{Role[{my_variable}].position}
The invite variable gives you access to the properties of a specific invite to the server. You can access its information by enclosing a invite in square brackets ({Invite[botghost].expiresAt}
).
For example:
{Invite[botghost].createdAt}
{Invite[9UPM6S4xyA].channel}
{Invite[{BGVAR_custom_variable}].maxUses}
{Invite[{my_variable}].uses}
BotGhost offers some variables you can use for any array or collection (even from an API response), which allow you to retrieve specific information of the collection.
{lowestValue({BGVAR_collection})}
Returns the lowest value in a collection.
{highestValue({BGVAR_collection})}
Returns the highest numerical value in a collection.
{lengthOfCollection({BGVAR_collection})}
Returns the length of a collection.
{valueAtPosition({BGVAR_collection}),[2]}
Returns the value at a specific position in the collection. Positions start at 0.
{positionOfValue({BGVAR_collection}),[hello]}
Returns the position of a value.
{collectionCharacterLength({BGVAR_collection})}
Returns the total character length of a collection.
{printAllValues({BGVAR_collection}),[Hello $value]}
Prints all values in a collection. The text returned can be set in the []. Use $value
to print the value, and $index
to display the index of the value shown.
{getRandomFromCollection({BGVAR_collection})}
Returns a random value from the collection.
{user}
Returns the mention of the user
<@1085541861692813332>
{server}
Returns the server name
BotGhost👻
{channel}
Returns the mention of the channel
<#879733469452836864>
{^ROLE NAME}
Returns the mention of a role on role name
<@&1190298492661420163>
{#CHANNEL NAME}
Returns the mention of a channel on channel name
<#879733469452836864>
{channel_name}
Returns the name of the channel
general-chat
{channel_type}
GUILD_TEXT
{channel_id}
Returns the ID of the channel
879733469452836864
{first_channel_id}
Returns the first channel ID of the server
879733469452836864
{server_members}
Returns the server member count
12
{server_icon}
Returns a URL to the server icon
{server_id}
Returns the ID of the server
822426820447567872
{server_owner}
Returns the mention of the server owner
<@136327647792726016>
{server_owner_id}
Returns the ID of the server owner
136327647792726016
{user_icon}
Returns the icon of a user
{user_name}
Returns the user name of a user
tomtoise
{user_id}
Returns the ID of a user
136327647792726016
{user_tag}
Returns the user tag of a user
{user_discriminator}
Returns the discriminator of a user
#4001
{user_createdAt}
Returns the creation date of a user
Fri Apr 08 2022 13:51:34 GMT+0000 (Coordinated Universal Time)
{user_joined}
Returns the join date of the server from a user
Fri Apr 08 2022 13:51:34 GMT+0000 (Coordinated Universal Time)
{user_displayName}
Returns the display name of a user
Tomtoise
{user_status}
Returns the status of a user
online
{random[min,max]}
Returns a random number between min and max
6
{isNumber(TEXT)}
Checks if a string of text is a number
true
{randomCharacters(3)}
Returns a random set of numbers
hIVzhLgwIb
{charCount(TEXT)}
Returns the character count of a string of text
16
{isBot}
Checks if a user is a bot
true
{bot_serverCount}
Returns the server count of the bot
12
{user_name_encoded}
Returns a URL encoded version of a user name, useful when sending the user's name in API request's URLs
Tomtoise
{time_now}
Returns a timestamp of the current time
<t:1724181552:R>
{time_ahead_h_HOURS}
Returns a timestamp of a certain number of hours ahead
<t:1724181552:R>
{time_ahead_m_MINS}
Returns a timestamp of a certain number of minutes ahead
<t:1724181552:R>
{time_now_unix}
Returns a unix combination of the current time
1724181974
{time_ahead_unix_h_HOURS}
Returns a unix combination of a certain number of hours ahead
1724181974
{time_ahead_unix_m_MINS}
Returns a unix combination of a certain number of minutes ahead
1724181974
{time_ahead_unix_s_SECS}
Returns a unix combination of a certain number of seconds ahead
1724181974
{encode_text[TEXT]}
Returns url encoded text for API requests
Hello%2C%20how%20are%20you
{ISO_to_UNIX[Timestamp]}
Converts an ISO timestamp to an UNIX timestamp
1724181974
{UNIX_to_ISO[Timestamp]}
Converts an UNIX timestamp to an ISO timestamp
2024-02-26T20:28:40.902000+00:00
{HEX_to_DECIMAL[HEX]}
Converts a hex code to a decimal
1329119
{solve_equation[1+1]}
Solve a math equation
2
{previous_numbers(10)}
Returns all previous numbers of a given number
0, 1, 2, 3, 4, 5, 6, 7, 8, 9
{bot_id}
Returns the ID of the bot
1085541861692813332
{hasRole([ROLE_ARRAY])}
Checks if the user has a set of roles
true
{isChannel([CHANNEL_ARRAY])}
Checks if the action is executed in a channel
true
{subString(Hello World),[0,5]}
Returns a substring of a given string
Hello
{toUpperCase(hello)}
Returns the given text to upper case
HELLO
{escape_characters[TEXT]}
Escapes the text provided to make it usable for API requests
Hello\nLine break
{websocket_ping}
Returns the ping of the bot
36 ms
{interaction_id}
Returns the ID of the interaction with the bot. This can be used in API requests to reply to interactions
1313779673350980230
{interaction_token}
Returns the token of the interaction with the bot. This can be used in API requests to reply to
A string of characters
Those variables can be used with the error handler block or success / error handles when something goes wrong with your tree.
{error_reason}
Returns the reason why the error occurred.
{error_message}
Returns the error message associated with the action the error occurred from.
{error_block}
Returns name of the block which the error occurred in.
You can view the available variables by checking the clipboard in the top right corner of each action. In the picture, the clipboard is indicated by the red arrow in a Plain Reply action.
The available variables in your command-builder or event-builder may vary depending on the action, custom variables you have, API requests you use, and the event you might be using in case you are using the event builder.
Event variables
Data storage variables
Form variables
API response variables
Error handler variables
You can use a set of variables when your command or event triggers an error. You can use these variables to get, for example, the error reason. They can be used only below the "Error Handler" red block.
Option variables
Unique variables
Success / error handler variables
You can use a set of variables when your action triggers an error. (If enabled) You can use these variables to get, for example, the error reason, message or action block.
Loop variables
Created channel variables
Created / edited thread variables
Invite variables
Manipulate some text variables
If you want to store data across all commands and events, you can use the , which allows you to store and retrieve data with different types of variables.
Through dot notation, you are able to access all the properties of the .
For a full list of properties make sure to checkout the properties section on the .
Through dot notation, you are able to access all the properties of the . For voice events, you can access properties of the .
For a full list of properties make sure to checkout the properties section on the .
Through dot notation, you are able to access all the properties of the .
For a full list of properties make sure to checkout the properties section on the .
Through dot notation, you are able to access all the properties of the .
For a full list of properties make sure to checkout the properties section on the .
Through dot notation, you are able to access all the properties of the .
For a full list of properties make sure to checkout the properties section on the .
Through dot notation, you are able to access all the properties of the
For a full list of properties make sure to checkout the properties section on the
Below are all basic variables that you can use in the .
Returns the of the channel
BotGhost Helper#4001
Depending on what type you use, you will have an other set of basic variables that you can use to retrieve specific information of the event. Check out the and pages to know more about webhooks and IFTTT variables.
Depending on what you have created, you will have an other set of data storage variables.
Depending on what you name your have, you will have an other set of form response variables.
Depending on what API request you use, you will have an other set of variables.
Depending on your names, you can have option variables in your command builder.
Depending on the that you use in your command or event and their names, you will have a set of unique variables.
You can use a few variables inside of a to get the loop count ({loop_count}
) and index ({loop_index}
).
Depending on the name of a create a channel action, you can use a set of variables to get the channel name, ID and type. Check out the page for more.
You can create a variable to retrieve the name, ID and more of the created / edited thread. Check out the and pages for more.
You can use a set of variables to get the codes from a created invite link. Check out the page for more.
You can use a variable of a name of your choice to get the result of the action.