Q:

using a variable in random to define max number generated

I am trying to make a discord bot that lets users roll dice with the user a user-defined maximum number
if(cmd === `${prefix}roll`|| cmd === `${prefix}Roll`){
       let ag = cmd.slice(5);
       message.channel.send("Roll The Dice!");
       var roll = Math.floor((Math.random()* ag) + 1);
       message.channel.send(roll);
    }

replacing ag in "Math.random()* ag" with something like 10 will work i am just confused if how i can get it to use a var
this dose not work and dose not return any errors in the terminal

A:

The problem is the value of ag. it will be a string if you slide the cmd
I am assuming you want to create a random number between 1-6
in that case, you can do
if(cmd === `${prefix}roll`|| cmd === `${prefix}Roll`){
       var ag = 6; // slice returns a string and the random generator works with a number.
       message.channel.send("Roll The Dice!");
       var roll = Math.floor((Math.random()* ag) + 1);
       message.channel.send(roll);
    }

Update 
if the user specifies a number in the cmd as !roll20 the above code will not execute at all because of the if (cmd ===${prefix}roll) check
if(cmd.startsWith(`${prefix}roll`) || cmd.startsWith(`${prefix}Roll`)){
       var ag = /\d+/g.exec(cmd); // get the digits in the value
       ag = ag ? ag[0] : 6 // check if there is a value or default to 6 
       message.channel.send("Roll The Dice!");
       var roll = Math.floor((Math.random()* ag) + 1);
       message.channel.send(roll);
    }

