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

Notifications

Announcements

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
    12,982 Super User 2025 Season 2 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
    12,982 Super User 2025 Season 2 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
    12,982 Super User 2025 Season 2 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,443 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard