Using variables

Variables are used to store data, Custom Command supports two main types of variables: temporary and permanent.


Temporary variables are usually deleted right after execution, can be accessed really easily, and are commonly used when editing the data.

How to use them?

  • $let - to define temporary variables
  • $get - to get value of temporary variable

Also temporary variables can be accessed by typing their name prefixed by a dollar sign. For example: $name will return the value of name variable.


Here are some examples of using temporary variables

1. Basic usage

In this example we will save information about Bob, and send a text with all the info in it:

// Save Bob's information
$let[workplace;a local supermarket]

// Send Bob's description
I am $name, and I am $age years old.
I work as a $job at $workplace.

Let's see what would be the output:

Custom Command Bot 05/28/2024
I am Bob, and I am 23 years old.
I work as a cashier at a local supermarket.

As you can see all variables have been replaced by their corresponding values.

2. Saving function output

Variables do not always have to keep a fixed text or number, you may also include a function when defining a variable. Let's use temporary variables to save different parameters of a word command.

Command we are going to work on will be report command used in the following way:

!report [User] [Reason]

So we will use the following code:

/* Note: 
    $user would interfere with a default $user function. 
    We will have to use $get function. 

$mention has reported $get[user] for $reason

Now, let's see what the output will be:

!report @fajfaj Breaking server rule number 5.
Custom Command Bot 05/28/2024
@Member has reported @fajfaj for Breaking server rule number 5.

You can see all the message parameters have been printed out successfully.


As the name suggests, permanent variables remain after executions. In CC, permanent variable can be attached to one of a few discord components.

  • Server - one value for the whole server
  • Channel - one value for each channel
  • User - one value for every user
  • Message - one value for each message

How to define one?

All functions used to define & access permanent variables follow the same naming convention:


For example, to set a message variable, you would use:



Here are some examples of putting permanent variables into reality

Where is the data stored?

Permanent variables are not stored within discord, they are kept in Custom Command's database. If you are concerned about privacy please refer to the Privacy Policy.

1. Server

Let's define a server variable called welcomeMsg containing content of welcome message.

!!exec $setServerVar[welcomeMsg;Welcome to the server!]

Now we will create a !hello command that will retrieve value of the variable we defined before.


Let's see if it works

Custom Command Bot 05/28/2024
Welcome to the server!

2. Channel

As you are familiar with server variables, it's time to hop on to channel variables. Different channels may have different values of the same channel variable.

Let's define description channel variable for two channels, and let users read them with !channel command.

!!exec $setChannelVar[description;A perfect place to ask for help with Custom Command;$channelID[Help]]

$setChannelVar[description;Channel for using bot commands without spamming the general chat;$channelID[Bots]]

Now we will create a code that will send description of chosen channel:


Let's see the output for two channels we set before.

!channel #Help
Custom Command Bot 05/28/2024
A perfect place to ask for help with Custom Command
!channel #Bots
Custom Command Bot 05/28/2024
Channel for using bot commands without spamming the general chat

You can see that different channels received different values of the same description variable.

3. User

Another type of permanent variables are user variables. As the name suggests the same user variable can have varying values among users.

This example will show user variables by creating an !aboutMe command that allows users to set their own descriptions.

!aboutMe command

Let's start of by creating a command for setting a description

// Set the description to "aboutMe" variable

// Send confirmation text
Your about me has been set successfully

Now two different members, Member, and Steve will set their descriptions:

!aboutMe Hi, my name is Member!
Custom Command Bot 05/28/2024
Your about me has been set successfully
!aboutMe What's up? I'm Steve
Custom Command Bot 05/28/2024
Your about me has been set successfully

Both users' descriptions have been saved to the description variable.

!profile command

Now let's make a command allowing users to check each others' profiles.

// Author embed field
$title[$username[$mentioned[1]]'s profile]

// Load description from user var

It's time to see if !profile command returns the correct descriptions

!profile @Member
Custom Command Bot 05/28/2024
Member's profile
Hi, my name is Member!
!profile @Steve
Custom Command Bot 05/28/2024
Steve's profile
What's up? I'm Steve

4. Message

If you read the previous sections carefully, you should already get the idea of permanent variables. Message variables work in the same way as other types do, but can be attached to a single message.

Here we will make a nickname change request command, that will allow button handler to access requested nickname.

!nickChange command

Let's start by creating a command users will use to request nickname change. We want the command to:

  1. Load requested nickname
  2. Send request prompt to a staff channel
  3. Save the requested nickname, and author of the request inside a message variable

// Save requested nickname to $let variable

// Send a prompt to #staff
    $mention has requested a nickname change to `$requestedNick`

// Save the nickname in a message var (with a name of "nick") attached to the prompt message ($sentMessageID)
// Store the requesting user

// Confirm submission
Your request has been submitted successfully, we will let you know once it gets approved.

Using !nickChange command will now send a message to #staff channel like this:

Approve button handler

As we have the proper message sent to the #staff channel, we have to make a command to handle the approve button.

Let's create a new command with button trigger.

The code has to:

  1. Grab new nickname and requesting user from message variables
  2. Change the nicknamee
  3. Notify user in the #bots channel
  4. Disable the approve button
// Save the new nickname to a $let variable

// Grab the user ID

// Change nickname

// Notify the user
    <@$usrID> your nickname has been changed to `$nick`

// Disable the approve button

Now the command will successfully grab the saved data, and use it to change user's nickname.

Message ID

It's worth noticing that in this command we did not provide any message ID. That's because the default value of the third parameter is $messageID which is ID of the message that triggered the command.

Server owner

Keep in mind that discord doesn't allow bots to change server owner's nickname. If server owner executes this command, the bot will reply with an error message.