# Dice Roller

**URL:** https://meta.discourse.org/t/dice-roller/170679
**Category:** Theme component
**Tags:** end-of-life, dice-roller
**Created:** [November 19, 2020, 11:49pm UTC](https://meta.discourse.org/t/dice-roller/170679 "2020-11-19T23:49:34Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Discourse](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/discourse/32/148734_2.png) [@Discourse](https://meta.discourse.org/u/Discourse)
#### Post date: [November 19, 2020, 11:49pm UTC](https://meta.discourse.org/t/dice-roller/170679/1 "2020-11-19T23:49:34Z")

</div>

| | | |
| --- | --- | --- |
| :discourse2: | **Summary** | **Dice Roller** adds a well-featured dice roller to your Discourse posts, for your forum-based game needs! |
| 🛠 | **Repository Link** | [https://github.com/discourse/discourse-dice](https://github.com/discourse/discourse-dice) |
| 📖 | **New to Discourse Themes?** | [Beginner’s guide to using Discourse Themes](https://meta.discourse.org/t/beginners-guide-to-using-discourse-themes/91966) |

Install this theme component

> [@](#):
>
> :discourse2: As this is an #official theme component maintained by the Discourse team, #Support, #Contribute > Bug, #Contribute > UX, and #Contribute > Feature requests can be made in the respective categories here on Meta, and tagged with the appropriate theme component tag. Click on a link below to get one started. 👍
> 
> [❓&nbsp; **Support**](https://meta.discourse.org/new-topic?category_id=6&tags=dice-roller "Ask for support on configuring and using Dice Roller") [🐛&nbsp; **Bug**](https://meta.discourse.org/new-topic?category_id=1&tags=dice-roller "A bug report means something is broken, preventing normal/typical use of the theme component") [👀&nbsp; **UX**](https://meta.discourse.org/new-topic?category_id=9&tags=dice-roller "Discussion about the user interface of Dice Roller, and how features are presented (including language and UI elements)") [💡&nbsp; **Feature**](https://meta.discourse.org/new-topic?category_id=2&tags=dice-roller "Discussion about how existing Dice Roller features can be improved or enhanced, and how proposed new features could work")

> ℹ Admins: Consider disabling the `discourse narrative bot disable public replies` setting after installing, as this theme component entirely supersedes the bot’s dice rolling behavior.

### 🎲 Basic Usage

The theme component interprets rolls formatted as `[wrap=dice]`.

```plaintext
[wrap=dice]d20[/wrap]
[wrap=dice]d100[/wrap]
[wrap=dice]2d6[/wrap]

```

 ![image](https://global.discourse-cdn.com/meta/original/3X/1/b/1b861bd200366d37585a169c047ef752f5a470a4.png)

You can roll multiple dice of the same type, apply additive modifiers, and automatically check the result against a success threshold:

```plaintext
[wrap=dice]2d6+3t12[/wrap]

```

![image](https://global.discourse-cdn.com/meta/original/3X/8/9/89c4bfe84411d3c6b49e94429f6dad1555799ebf.png)

### 👩‍🔬 Advanced Features: Crits, Split Rolls

You can specify specific _natural_ rolls to be treated as “critical hits” with the `crit=` option. Critical hits are checked **before** the additive modifier.

```plaintext
[wrap=dice crit=1,100]1d100[/wrap]
[wrap=dice crit=1,20]d20+3[/wrap]

```

![image](https://global.discourse-cdn.com/meta/original/3X/1/7/17fd52b1feca1c76a0e27feb6f35a140cc1504d1.png)

> If particular crit values are notable on your forum, an admin can add extra CSS to emphasize them. In this example, crits that roll a `1` are colored in red.

If you’re allowing multiple rolls to be checked against the same threshold, you can add the `i` **Individual** modifier in conjunction with `t` **Thresholds**. The number of successful dice that passed the threshold will be summarized at the end.

```plaintext
[wrap=dice]5d100t60i[/wrap]
[wrap=dice]3d20-5t0i[/wrap]

```

 ![image](https://global.discourse-cdn.com/meta/original/3X/9/1/916c3e01211ca9b0c51b52a48be8eb0e087fa936.png)

> ℹ Currently, the pre-modifier rolls are shown. This may change in the future depending on feedback.

### ⛔ Restrictions

To avoid griefing with large post bodies, a maximum number of dice per roll is available in the **theme settings** for the admin to adjust. The default is **80** dice.

0-sided and 1-sided dice are not allowed. Rolling 0 dice is not allowed, and dice with more than ~67 million faces are not allowed for performance reasons.

### ⚙ Technical Details, and Cheating

Rolls are calculated in JavaScript using a RNG seeded by the post’s ID and creation timestamp, going in order through the post body. Roll values are not visible before the post is created.

Several special formatting styles are applied to rolls, to distinguish them from normal text in posts. This doesn’t stop people from posting images!

Roll values are **not** saved in the post body automatically. This presents a problem for archival needs. Solutions to this will require use of a plugin.

If you need to edit additional die rolls into your post, they **must be added at the bottom** to preserve the results of all previous rolls. Adding new die rolls at the top of a post will randomize the results of all the rolls. For this reason, having **any erroneous rolls** in a post will prevent all subsequent rolls from functioning.  
The composer preview will tell you if your dice specification is 🎲 correct or ⚠ erroneous.

 ![image](https://global.discourse-cdn.com/meta/original/3X/5/e/5ef8dec55b37c9613f9d5ea9c3d77e842e37b2da.png)

While these measures can help prevent accidental cheating, a determined cheater can try to predict when they should submit their post. If you’re considering this for anything valuable, have a trusted user who cannot receive the reward author the post, or use an independent source like [https://random.org](https://random.org) , which offers paid services for auditable drawings and raffles.

Remember to _have fun_!

### Settings

| Name | Description |
| --- | --- |
| max dice | |

| Translation | Default |
| --- | --- |
| dice.result.success\_count.one | (%{count} Success) |
| dice.result.success\_count.other | (%{count} Successes) |
| dice.excessive.quantity.one | Excessive dice quantity (max %{count}) |
| dice.excessive.quantity.other | Excessive dice quantity (max %{count}) |
| dice.excessive.faces | Number of die faces cannot exceed 67,000,000 |
| dice.missing.faces | Invalid die specification: missing number of faces |
| dice.invalid.generic | Invalid die specification. Format: 2d20+3 |
| dice.invalid.quantity | Number of dice cannot be 0 |
| dice.invalid.faces | Number of die faces cannot be 0 or 1 |
| dice.invalid.modifier | Modifier cannot be 0 |
| dice.invalid.threshold | Threshold cannot be 0 |
| dice.invalid.crits | Bad numbers in crits attribute. (Should be crits=4,5,6) |
| dice.invalid.halt\_after\_error | Rolling halted due to earlier error. Fix errors to view results. |

  

> :discourse2: **Hosted by us?** Theme components are available to use on our Standard, Business, and Enterprise plans.

> Last edited by @david 2025-06-16T09:11:30Z
> 
> > **Check document**
> >
> > Perform check on document:

---

<div class="post-metadata">

### Author: ![hugh](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/hugh/32/336717_2.png) [@hugh](https://meta.discourse.org/u/hugh)
#### Post date: [September 6, 2024, 4:38am UTC](https://meta.discourse.org/t/dice-roller/170679/5 "2024-09-06T04:38:54Z")

</div>

If anyone is interested in implementing a more versatile dice roller in Discourse using an AI persona, I did this on a community I manage and it works excellently. I set up an AI persona and allowed it to use the Random Picker tool, set the ‘max context posts’ setting to 1, and gave it these instructions:

> [@](#):
>
> You are Random Picker Bot who specialises in rolling dice.
> 
> - You have access to the Random Picker function to get truly random results.
> - Users will invoke you when they need to roll a die with a specified number of sides.
> - Users will specify a die to roll, sometimes also saying how many, and whether you should add other modifiers to the result.
> 
> Dice:  
> Dice are identified by the letter d followed by a number, the result of the die could be anything from 1 up to that number. For example, if the user says “d8”, you will roll an 8-sided die and return a single number from 1-8.
> 
> Percentage die:  
> The user may use the % symbol for the type of die, like this: d%. In that case, roll a random number from this set [0,10,20,30,40,50,60,70,80,90].
> 
> Numbers of dice:  
> The user may specify a number before the type of die, for example: “2d10”. In that case, roll that many dice, and display each result as well as the total that they add up to in an equation.
> 
> Modifiers:  
> The user may specify a mathematics operator (either + or -) and number after the type of die - this is called the “modifier”. In that case, find the result of the die roll and then do the maths. Output the die roll and the full equation, with the answer.
> 
> Using dice as modifiers:  
> The user may specify a type of die to use as a modifier. In that case, roll that die and add it to the result like a normal modifier.
> 
> Multiple rolls:  
> Treat each line in the input as an independent request and generate output for each one individually.
> 
> Combining dice:  
> The user may specify two dice with “and” or “&” in between them. In that case, do not add them together, but output the result like this: [first die roll] & [second die roll] = [first die roll][second die roll]. Do not put a space between the final numbers.
> 
> Advantage:  
> The user may use the word “advantage” or “disadvantage” at the end of the roll input. When that happens, make the specified roll twice and don’t add them together. Output the higher result on the first line, preceded by "🎲 Higher: ". Output the lower result on the second line, preceded by "🎲 Lower: ".
> 
> Any part of the output that shows the result of a die roll must be **bold**.
> 
> Here are some input examples with the expected output:
> 
> Input: 2d20  
> Output:  
> [random number from 1-20] + [random number from 1-20] = [total]
> 
> Input: d12+7  
> Output:  
> [random number from 1-12] + 7 = [total]
> 
> Input: 3d10-2  
> Output:  
> [random number from 1-10] + [random number from 1-10] + [random number from 1-10] - 2 = [total]
> 
> Input: d6+d8  
> Output:  
> [random number from 1-6] + [random number from 1-8] = [total]
> 
> Invoke Random Picker and then respond with the results. Output the result in a block quote in this format:
> 
> Rolling **[input here]**:
> 
> > 🎲 [output here]
> 
> Some guidelines:
> 
> - Only use Random Picker once for each roll.
> - If you cannot interpret the request, say “Invalid dice format - please try again.”
> - If you encounter any other error, say “Error - please try again.”

I connected the persona with a user (in this case `@dice`), so it can be invoked in any post by saying something like `@dice 3d6`, and the bot will reply with the result. You can see it in action in [this topic of my community](https://tinytails.community/t/rolling-dice-on-the-forum/136) (if you’re interested in tabletop gaming, feel free to join the community - it’s very new still).

Of course, this uses AI, so it requires an LLM API key. I’m using GPT-4o-mini, so the cost is very low, especially for the volume I’m looking at here.

---

<div class="post-metadata">

### Author: ![happycactus](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/happycactus/32/328435_2.png) [@happycactus](https://meta.discourse.org/u/happycactus)
#### Post date: [January 20, 2026, 9:14am UTC](https://meta.discourse.org/t/dice-roller/170679/6 "2026-01-20T09:14:57Z")

</div>

For those who might be interested, I updated the original component for the new API. I didn’t want to use a LLM to roll a simple dice, or the bot, I liked the original component so much…

Anyway, I had to ask claude to help, so if anyone spot AI BLABLABLA, yeah, you are right, I confess. I used it.

For those that are still interested, [I am hosting the fork](https://github.com/studiofuga/discourse-dice) (the original git was archived.)

Looking forward for feedback and critics (or even insults, I don’t care).
