value|roll
Whether or not to notify other players of the results when extracting random numbers. If this is value
, then the results are displayed only to the player using the command. If this is roll
, then the results are revealed to all players.
from Minecraft Wiki
As shown in the quote, /random roll
already tells all players "[player] rolled a [number] (from 1 to 20)", however, if you want to display this in a custom way (e.g. An [number] was rolled!), then you need to first create a scoreboard to store the randomly rolled value:
/scoreboard objectives add random dummy
(You can call the scoreboard any name, in this case it's "random".)
Then you can roll a random number and store it to the scoreboard using /execute
:
/execute as @s store result score Random random run random value 1..20
(Use random value rather than random roll, otherwise it will tell all players before you run the last command, which will use the "[player] rolled a [number] (from 1 to 20)".)
Finally, you can run this command to send a chat message to all players that includes the scoreboard value:
/tellraw @a [{"text":"An "},{"score":{"name":"Random","objective":"random"}},{"text":" was rolled"}]
To change the text, use this base command:
/tellraw @a [{"score":{"name":"Random","objective":"random"}}]
Then add {"text":"[text contents]"} as many times as needed, replacing [text contents] with whatever text you need. Make sure to seperate each section with commas.
Source: Minecraft wiki and in-game testing.