Home > Net >  Discord.js Randomiser Command Ignoring Minimum and Maximum Values
Discord.js Randomiser Command Ignoring Minimum and Maximum Values

Time:01-19

I have this Discord bot here that contains a randomiser command - /random (built with new SlashCommandBuilder) - and consists of two required string options - min and max values.

This code...

run: async (bot, interaction, args) => {
        const min = interaction.options.getString('min').replace(/[^\d.-]/g, '')
        const max = interaction.options.getString('max').replace(/[^\d.-]/g, '')

        parseFloat(min, parseFloat(max))

        random = Math.floor(Math.random() * (max - min)   min)

        console.log(min, max)

        interaction.followUp({ content: `${random}` })
        
    }

...extracts the strings from the user's interaction and parses them into floats. The expected result consists of a random number between the min value and the max value.

However, the randomiser does not use the min or max value and instead prints a random number regardless of what the user inputs.

I predict that is quite an inefficient method of a randomiser command. I kindly suggest assistance, and (if) any will be greatly appreciated!

Note: An error does not occur upon command exection.

CodePudding user response:

You should use enter image description here enter image description here

  •  Tags:  
  • Related