Skip to content

$(math)

Syntax
$(math <expression>)
Arguments
Required

The $(math) variable allows you to perform mathematical calculations and operations directly in your StreamElements Chatbot messages. It utilizes the math.js library, providing a wide range of mathematical functions and capabilities.

!command add !calc Result: $(math $(1:))
Example chat
ViewerName:!calc 2 + 2
partner badgemoderator badgeStreamElements:Result: 4

To use the $(math) variable, include it in your message followed by a valid math.js expression:

$(math <expression>)

Replace <expression> with the mathematical operation you want to perform. Results are plain numbers like 4, -1, or 0.05 — and unit conversions return values like 5 inch.

Rounding a division result

10 divided by 3, rounded to the nearest integer, is $(math "round(10/3)")
Example chat
partner badgemoderator badgeStreamElements:10 divided by 3, rounded to the nearest integer, is 3

Generating a random number

Your random number between 1 and 10 is $(math "random(1,10)")
Example chat
partner badgemoderator badgeStreamElements:Your random number between 1 and 10 is 7.525986609745358

The $(math) variable takes a single parameter: a valid math.js expression. This can include:

  • Basic arithmetic operations (+, -, *, /)
  • Mathematical functions (e.g., round(), floor(), ceil(), log(), sin(), cos())
  • Constants (e.g., pi, e)
  • Logical operators (e.g., >, <, ==, !=)

For a complete list of supported operations and functions, refer to the math.js documentation.

Bot reply Cause
Something went wrong while processing equation The request to the math service failed
Failed to evaluate equation The result could not be read

Invalid expressions return the error text produced by the math service itself.

  • $(customapi): Can be used to fetch and process numerical data from external sources

Q: Can I use variables in my math expressions?

A: Yes, you can use other StreamElements variables within your $(math) expression. For example: $(math $(user.points) * 2) would output double the user’s points.

Q: Is there a limit to the complexity of expressions I can use?

A: While there’s no strict limit, very complex expressions may take longer to process, and results are truncated to the first 400 bytes. It’s best to keep expressions relatively simple for optimal performance.