calc
Calculator Custom Command made by @Asty'. Features: • Displays the result of your equation when valid • Displays an error message when the input is not a valid equation • Truncates the result conditionally (only when it ends in .0, otherwise returns the decimal result) • Adds commas every 3 digits in the result for better readability • Spaces in the input are sanitized and won't disturb the equation • Ability to use TagScript's math functions in the input, such as trunc(), round(), etc. See the documentation for more info • Ability to add "k" for thousands and "m" for millions in the input (such as 1m+2k-3.4) Requested Edits: (re-import the command for the edits to apply!) • Now supports things like 1.2m and 3.4k, thanks to @Elise's discovery • Now also supports ÷ to divide and x to multiply • Now supports square root, if the word sqrt is specified after what it should square root. Such as (20+5)sqrt or 25sqrt. So typing sqrt(5) won't work! Note: You can import it as "calc" and add a shorter alias to it such as "c" with "[p]tag a c calc" if you want to, so both could be used by your members for the same tag.
Content
22 lines{=(largs):{lower:{args}}}
{=(COMMENT):This is the part that does the math based on the user input, truncatenates conditionally, puts commas every 3 digits in the result, and replaces the output with an error message when the input was invalid. All of that in that one single line and with no "if" block whatsoever.}
{=(equation):{replace(Z,):{replace(.0Z,):{m:{replace(π,pi):{replace(sqrt,^(1/2)):{replace(÷,/):{replace(x,*):{replace(m,e6):{replace(k,e3):{replace( ,):{largs}}}}}}}}}Z}}}
{=(equation):{replace(<o error>,Error. Invalid input.):{replace(st,):{replace(nd,):{replace(rd,):{replace(th,):{ord:{equation(1):.}}{if({equation(2+):.}!=):.{equation(2+):.}}}}}}}}
{=(COMMENT):Title and thumbnail of the embed.}
{=(title):Calculator}
{=(thumbnail):{replace(1200px,250px):https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/GNOME_Calculator_icon_2018.svg/1200px-GNOME_Calculator_icon_2018.svg.png}}
{=(COMMENT):Conditional input to display. Returns a space when no argument is provided, just so it doesn't display two "`" characters.}
{=(input):{if({1}==):None.|{replace( ,):{largs}}}}
{=(COMMENT):Conditional output to display.}
{=(error):You need to specify an equation to calculate.}
{=(output):{if({1}==):{error}|{equation}}}
{=(COMMENT):Conditional embed's side color. Red if no argument or invalid input; otherwise gray/transparent.}
{=(clr.red):F80E0E}
{=(clr.gray):2f3136}
{=(em.color):{if({1}==):{clr.red}|{if({in(Error. Invalid input.):{equation}}==true):{clr.red}|{clr.gray}}}}
{embed(color):#{em.color}}Embed
1 line{"color": 5198940, "title": "{title}", "fields": [{"name": "Input", "value": "`{input}`", "inline": false}, {"name": "Output", "value": "`{output}`", "inline": false}], "thumbnail": {"url": "{thumbnail}"}}Raw JSON
{
"id": 365946,
"created_at": "2020-10-09T06:24:04.000Z",
"tag_name": "calc",
"nsfw": false,
"owner_id": "149926720114262016",
"uses": 188,
"description": "Calculator Custom Command made by @Asty'.\n\nFeatures:\n• Displays the result of your equation when valid\n• Displays an error message when the input is not a valid equation\n• Truncates the result conditionally (only when it ends in .0, otherwise returns the decimal result)\n• Adds commas every 3 digits in the result for better readability\n• Spaces in the input are sanitized and won't disturb the equation\n• Ability to use TagScript's math functions in the input, such as trunc(), round(), etc. See the documentation for more info\n• Ability to add \"k\" for thousands and \"m\" for millions in the input (such as 1m+2k-3.4)\n\nRequested Edits: (re-import the command for the edits to apply!)\n• Now supports things like 1.2m and 3.4k, thanks to @Elise's discovery\n• Now also supports ÷ to divide and x to multiply\n• Now supports square root, if the word sqrt is specified after what it should square root.\n Such as (20+5)sqrt or 25sqrt. So typing sqrt(5) won't work!\n\nNote: You can import it as \"calc\" and add a shorter alias to it such as \"c\" with \"[p]tag a c calc\" if you want to, so both could be used by your members for the same tag.",
"restricted": false,
"shared": true,
"deleted": false,
"safe": "unrated",
"hidden": false,
"guild_id": "314660900302749696",
"sharer": "149926720114262016",
"content": "{=(largs):{lower:{args}}}\n\n{=(COMMENT):This is the part that does the math based on the user input, truncatenates conditionally, puts commas every 3 digits in the result, and replaces the output with an error message when the input was invalid. All of that in that one single line and with no \"if\" block whatsoever.}\n{=(equation):{replace(Z,):{replace(.0Z,):{m:{replace(π,pi):{replace(sqrt,^(1/2)):{replace(÷,/):{replace(x,*):{replace(m,e6):{replace(k,e3):{replace( ,):{largs}}}}}}}}}Z}}}\n{=(equation):{replace(<o error>,Error. Invalid input.):{replace(st,):{replace(nd,):{replace(rd,):{replace(th,):{ord:{equation(1):.}}{if({equation(2+):.}!=):.{equation(2+):.}}}}}}}}\n\n{=(COMMENT):Title and thumbnail of the embed.}\n{=(title):Calculator}\n{=(thumbnail):{replace(1200px,250px):https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/GNOME_Calculator_icon_2018.svg/1200px-GNOME_Calculator_icon_2018.svg.png}}\n\n{=(COMMENT):Conditional input to display. Returns a space when no argument is provided, just so it doesn't display two \"`\" characters.}\n{=(input):{if({1}==):None.|{replace( ,):{largs}}}}\n\n{=(COMMENT):Conditional output to display.}\n{=(error):You need to specify an equation to calculate.}\n{=(output):{if({1}==):{error}|{equation}}}\n\n{=(COMMENT):Conditional embed's side color. Red if no argument or invalid input; otherwise gray/transparent.}\n{=(clr.red):F80E0E}\n{=(clr.gray):2f3136}\n{=(em.color):{if({1}==):{clr.red}|{if({in(Error. Invalid input.):{equation}}==true):{clr.red}|{clr.gray}}}}\n{embed(color):#{em.color}}",
"embed": "{\"color\": 5198940, \"title\": \"{title}\", \"fields\": [{\"name\": \"Input\", \"value\": \"`{input}`\", \"inline\": false}, {\"name\": \"Output\", \"value\": \"`{output}`\", \"inline\": false}], \"thumbnail\": {\"url\": \"{thumbnail}\"}}",
"last_fetched": "2026-10-20T22:42:35.144Z"
}