Variables

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 custom command and event builder.

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.

Targeting

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 works slightly different for object variables. For more information, click here.

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

Options

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

Variables Containing an ID

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

Storing Custom Data

Storing Data across all commands and events

If you want to store data across all commands and events, you can use the data storage, which allows you to store and retrieve data with different types of variables.

Storing Data in a command or event

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.

Variables

Object Variables

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}

Guild Variable

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}).

Through dot notation, you are able to access all the properties of the Discord.js Guild Object.

For example:

  • {Guild.name}

  • {Guild[822426820447567872].name}

  • {Guild.roles}

  • {Guild.bans}

  • {Guild.icon}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

Channel Variable

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.

Through dot notation, you are able to access all the properties of the Discord.js Channel Object. For voice events, you can access properties of the Voice Channel.

For example:

  • {Channel.name}

  • {Channel[1111802548312096778].name}

  • {Channel.type}

  • {Channel.id}

  • {Channel.position}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

Member Variable

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}).

Through dot notation, you are able to access all the properties of the Discord.js GuildMember Object.

For example:

  • {Member.user.username}

  • {Member[136327647792726016].user.username}

  • {Member.avatar}

  • {Member.roles}

  • {Member.presence}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

User Variable

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}).

Through dot notation, you are able to access all the properties of the Discord.js User Object.

For example:

  • {User.username}

  • {User.globalName}

  • {User.avatar}

  • {User.banner}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

Role Variable

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}).

Through dot notation, you are able to access all the properties of the Discord.js Role Object.

For example:

  • {Role[905462520519745537].icon}

  • {Role[option_role].name}

  • {Role[{event_role_id}].hoist}

  • {Role[{my_variable}].position}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

Invite Variable

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}).

Through dot notation, you are able to access all the properties of the Discord.js Invite Object.

For example:

  • {Invite[botghost].createdAt}

  • {Invite[9UPM6S4xyA].channel}

  • {Invite[{BGVAR_custom_variable}].maxUses}

  • {Invite[{my_variable}].uses}

For a full list of properties make sure to checkout the properties section on the Discord.js Wiki.

Basic Vars

Below are all basic variables that you can use in the command or event builder.

VariableDetailsSupports TargetsExample Output

{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}

Returns the type of the channel

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

BotGhost Helper#4001

{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

Other vars

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.

VariablesDetails

Event variables

Depending on what event 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 Webhooks and IFTTTpages to know more about webhooks and IFTTT variables.

Data storage variables

Depending on what custom variables you have created, you will have an other set of data storage variables.

Form variables

Depending on what you name your form actions have, you will have an other set of form response variables.

API response variables

Depending on what API request you use, you will have an other set of 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

Depending on your option names, you can have option variables in your command builder.

Unique variables

Depending on the unique variables that you use in your command or event and their names, you will have a set of 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

You can use a few variables inside of a loop to get the loop count ({loop_count}) and index ({loop_index}).

Created channel variables

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 Create a channel page for more.

Created / edited thread variables

You can create a variable to retrieve the name, ID and more of the created / edited thread. Check out the Create a Thread and Edit a Thread pages for more.

Invite variables

You can use a set of variables to get the codes from a created invite link. Check out the Create Server Invite page for more.

Manipulate some text variables

You can use a variable of a name of your choice to get the result of the Manipulate some text action.

Last updated