Discord Command Variables


Discord Custom Commands Tag Guideline:

These command variables can be used in any custom command.

e.g: !addcom !hello Hello, (sender)

(sender) - User who triggered the command.

(@sender) - User who triggered the command, but will ping the sender.

(touser) - Replaces with the first argument you say after the command. If nothing is said after it will be the user who triggered the command.

(#) - Random number from 0 to 100.

(1) - Command argument. You can change the one to another number to get that argument. This is limited to 9 arguments.

(1=STRING) - First command argument. If the first argument is empty it will replace it with string you want, this string can be a command variable.

(random) - Chooses a random person in Discord.

(uptime) - Current stream uptime.

(game) - Current game set on Twitch.

(status) - Current title set on Twitch.

(viewers) - Current viewers on Twitch.

(follows) - Current followers on Twitch.

(echo) - Will say anything as the bot.

(readfile FILE_NAME) - Will read a text file by the given name. Note it must be in the bots addons folder.

(writefile FILE_NAME, APPEND, TEXT) - Will write the text to that file, note that most of the tags will work in the text.

(file FILE_NAME) - Uploads a file to Discord.

Custom API and Custom API JSON:

To allow for a great deal of flexibility with PhantomBot, we are happy to provide new tags for custom commands.

Custom API:

!addcom tag: (customapi URL)
URL may contain $1…$9 to pass parameters from chat as input to the URL.
The customapi tag will pull a given URL and display the information exactly as it is provided by the web service. This is useful for web services that return plain text. Do not use this to return data from a web page, as that will simply spam the chat. Note that the URL may be passed parameters from chat, for example, say a web service requires a text field to return data, such as a name of a person:

!addcom joke (customapi http://not.real.com/joke.php?name=$1)
This would send a request and pass name with a value given as the first parameter to !joke in chat. Note that if a $1…$9 parameter is given, the bot will require parameters before executing the command.

Custom API JSON:

!addcom tag: (customapijson URL key | object.key | object.object…key | {literal string} …)
URL may contain $1…$9 to pass parameters from chat as input to the URL.
key is a key to data on the first node of the returned JSON
object.key provides a JSON object to select a key from.
object.object…key indicates that many objects may be traversed to get at a given key.
{literal string} is text to place between queried values.

The customapijson tag will pull a given URL and expects to receive a JSON object from the web service. An understanding of JSON objects is highly recommended in order to know what to use as the mapping guide. Note that the JSON parser will not attempt to traverse arrays and find specific elements, this will only select objects and a key. The key must relate to an integer or string value. The following is an example:
!addcom yomomma (customapijson http://api.yomomma.info/ joke)

The above will create a new command that queries the given API and returns the value associated with the joke key.

Another example:

(customapijson http://api.apixu.com/v1/current.json?key=NOT_PROVIDED&q=$1 {Weather for} location.name {:} current.condition.text {Temps:} current.temp_f {F} current.temp_c {C})

The above will create a new command that queries the given API and requires a parameter to be given in to the command. In this instance, a weather API is queried and the return string will be:
Weather for city name: (current weather)
Temps: Temp in F, Temp in C

To step through a bit further:

location.name parses the top level location object and then returns the value associated with the name key.
current.condition.text parses the top level current object and then moves to the condition object to return the value associated with the text key.
current.temp_f and current_temp_c parse the top level current object and return the value associated with the given keys, temp_f and temp_c.
{Weather for}, {:}, {Temps:}, {F} and {C} are literal strings that are printed out.

Please note again, that this is a simple implementation for parsing JSON data. If a more complex JSON is to be parsed or data is to be correlated in some way, then a custom script or Java module would need to be developed.

Phantombot commands to work in discord