web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Creating command flow ...
Power Automate
Unanswered

Creating command flow for Dice Roll

(0) ShareShare
ReportReport
Posted on by 10

Hello, I'm new to Power Automate and I'm basically trying to create a bot to roll dice in a Group chat.

 

I got to a point where I'm just stuck, and I got nowhere else to go. This is the Input and Output i want:

 

Input Message: "/roll d20"

Output Message/Card: "You rolled a 17!"

 

And I'm just stuck, I had errors to get the message body, but now I'm stuck trying to do rand( 1 , int( slice( messagebody, 8, 3))+1)

Apparently i cannot sum 1 even after i converted the 20 value to an int (because rand() needs to sum+1 so that it can go up to 20)

 

Any ideas how to fix this? or even how to help me get the correct flow for this?

Thanks!

Categories:
I have the same question (0)
  • David_MA Profile Picture
    14,864 Super User 2026 Season 1 on at

    I am not really understanding what you want to do since a traditional six-sided dice has only six values from 1 to 6. How do you roll a 17? Or is that the problem you are having? If so, you can use the following expression to generate a number from 1 to 6:

     

    rand(1,6)

     

  • jomaor1 Profile Picture
    10 on at

    Hello, thanks for the reply!

     

    Sorry, maybe I wasn't too clear. There are OTHER dice sizes, so if the user types /roll d20, it should roll a dice with 20 sides. Which is very common in RPGs settings (DnD).

     

    Another problem is that you stated that rand(1,6) returns 1 through 6. This is incorrect, the function will return between 1 and 5. So I always need to sum 1 to the dice size the user chose.

     

    That's why it should be rand( 1, user_size + 1)

  • David_MA Profile Picture
    14,864 Super User 2026 Season 1 on at

    I don't think I am wrong with regard to rand(1,6) returning 1, 2, 3, 4, 5, and 6, but let's say I am. In that case, change the expression to rand(1,7). Then for your 20-sided dice, use rand(1,21)

  • jomaor1 Profile Picture
    10 on at

    Hello! 2 things:

     

    1 - Just ran a test with just a loop of 50 rand(1,6) and got 0 6's. So I need to sum 1 to the number.

    2 - The dice number is variable and should be chosen by the user. So I cannot just go with 1 IF() to see if it's 6 sided or 20 sided...

  • David_MA Profile Picture
    14,864 Super User 2026 Season 1 on at

    If the user is choosing how many sides the die has, use this expression:

    rand(1,add(int(triggerBody()['number']),1))

     

    You will replace triggerBody()['number'] with the dynamic content provided by the user.

  • CU27110513-0 Profile Picture
    2 on at
    I’ve messed around with this kind of thing before, and yeah, getting it to work can be a bit of a pain. The issue is that rand() doesn’t include the upper number unless you bump it up by 1. What worked for me was using something like this:
    rand(1, add(int(slice(triggerBody()['messagebody'], 8, 3)), 1))
    Basically, it grabs the number of sides (like the 20 from /roll d20), turns it into an integer, and adds 1 so it rolls the full range.
    If you want to double-check that it’s rolling properly, you could test it with a dice simulator first to make sure the numbers feel right.
  • Chriddle Profile Picture
    8,706 Super User 2026 Season 1 on at
    Just ran a test with just a loop of 50 rand(1,6) and got 0 6's. So I need to sum 1 to the number.
    Just read the documentation ;)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 463

#1
Valantis Profile Picture

Valantis 463

#3
11manish Profile Picture

11manish 264

Last 30 days Overall leaderboard