Skip to content

The Variable system

Casper1123 edited this page Apr 23, 2025 · 9 revisions

Welcome tot the wiki page on the variable system.
This page will be divided into the following segments:

  • Where to use variables
  • How to use variables
  • Regular variables
  • Command variables

Where to use variables

Variables are usable in many strings that the bot processes. The most important one of these is facts, but it also works on auto-replies, triggers, sayings, anything really. If you're interested in the code behind the processing, you can find it here.

How to use variables

Whenever you're adding a fact, variables are represented inside {}.

If you want to use { or } without calling a variable, put a \ before it (ex: \{ \}). This is mandatory if you still want to use variables in your message. This also works for variable indicating characters in command variables. (for example, using a " inside of a choice option: {choice:"this has a \" in it"}) For what variables exist or how they work, see below.
To use a variable, take for example this following fact that you could enter into /admin preview [fact]:
Hello {user.name}! I hope you've been having {choice:"a nice","an awesome"} day.
Keep in mind that you can still use Markdown styling to for example link a channel: <#{channel.id}>

Regular variables

Regular variables are predefined pieces of data that you can access without any arguments.
*For bot hosters: Some information is only usable inside of servers. If something is **not globally (so not in DMS)* usable, it will have an * added to it. These can still be used in anything freely, however they do not get replaced whilst in dms and might look uggly if you intend to use the bot for DMS only.

user

The user that triggered the response. This is either the caller of the command, or the sender of the message.

  • user.account the user's account name.
  • user.name the user's (nick)name.
  • user.id the user's account id.

guild

The server the command is ran in.

  • guild.id* the server's id.
  • guild.name* the server's name.

This also has the guild's owner. In case you ever need it. Don't be too annoying.

  • owner.account* the account name of the server's owner.
  • owner.name* the (nick)name of the server's owner.
  • owner.id* the account id of the server's owner.

self

Refers to the bot (and it's account) itself.

  • self.name the bot's name.
  • self.id the bot's id.
  • self.nick* the bot's nickname.

General

More general-purpose variables.

  • enter Adds a newline. you can also just put \n inside of a fact which works the same.
  • total_facts the sum of the local and global fact counts.
  • global_facts the count of global facts.
  • local_facts the count of local facts.

Command variables

Command variables (more commonly known as functions) take parameters to work properly. The type of parameters, and a couple examples, will be listed with their documentation.

rand:int,int

rand:int,int takes a lower and an upper int (no space behind the comma , ) and generates a random number between those (inclusive)

ex: {rand:1,5} is my lucky number.

choice:*str

choice:*str gives multiple options to select a random one from. The selection may contain variables.
Make sure to mark the ending of each option properly. The , in between is not mandatory, however using " or ' is. If you want to use these characters inside your choices safely, put a \ in front of it.

ex: {choice:"option1","option2 even has a variable: {rand:0,1}"}
ex: {choice:"This option has no choice."'{choice:'Stacked choices'"and interchanged bounding characters!"}'}

tru_[op]([num])

This command variable only works on servers.
tru (aka True Random User) ironically enough allows you to semi-randomly use user information.
It requires an operation and a number. Supported operations: name, acc, id where acc = account, the global default name of the user.
The server list is shuffled and the number is used to index this shuffled list. If the number is too large or small, it loops. This means that sometimes, two different numbers might equal the same user.
Throughout your entire statement (be it fact or something else), these users will stay the same, so no matter where you use tru, tru(0) will stay the same (hence why it's semi-random, you can always get the same random user if you please)

ex: <@{tru_id(0)}> challenges <@{tru_id(1)}> to a duel!
ex: {tru_name(0)} is cool.

Clone this wiki locally