Skip to content
Daniel Grace edited this page May 9, 2016 · 5 revisions

When you roll some number of dice in v2 via JavaScript, what you get back is not a string or a number. Instead, you get back a Roll object. If you want a string, it's as simple as getting the string property of that object, like so:

echo(roll("2d20").string);

For more advanced usage though, you will have to understand what properties are on the Roll object.

tokens

tokens is an array of top-level items that went into this roll. In the simple case of rolling 1d20, you would have but a single token: the actual die being rolled. Even in the case of 2d20, you only have a single token (though that token now has sub-tokens to represent each die). But if you get into 1d20+5, you now have three tokens: one to represent the die, one to represent the +, and one to represent the static number of 5. Each of these tokens are different.

There are several different types of tokens:

Die Token

Plus Minus Token

Number Token

string

This is the string that would have been executed if you just did a roll command instead of entering JavaScript mode.

ordered

Bot v1 displayed all dice results in order. That is, if you rolled a 1, a 3, and then a 2, it would display as 1, 2, 3. Use the .ordered property if you want that behavior back.

simple

simple is the result of the roll, surrounded by ` characters, such that Discord will display it as mono-spaced font. This is useful for certain macros.

plain

plain is the result of the roll as a number instead of a string. Use this if you want to continue to do math on the result instead of displaying it directly to the end user. Or if you want to display it to the end user with no formatting whatsoever.

Clone this wiki locally