繁体   English   中英

如何制作生成关闭用户输入的 discord.js 随机数生成器

[英]How do I make a discord.js random number generator that generates off user input

如何制作生成关闭用户输入的 discord.js 随机数生成器? 我一直在尝试这样做很长时间,但无法使用我的代码格式。

if (message.content == "<lottery") {
   let embed = new Discord.MessageEmbed()
       .setTitle("**Lottery Winner!**")
       .setDescription("The winner of the lottery's number is {The random number that is generated}")
       .setColor("RANDOM")
       .setFooter(`Congratulations!`)
 
       .setThumbnail('https://cdn.discordapp.com/attachments/800757031506149426/835360163782459422/OIP.png')
   message.channel.send(embed);
}

我如何以某种方式获得嵌入内的范围?

这应该适用于随机数

//Define this function somewhere in the code.
const RandomInt = (min, max) => { //Generates a random integer number
  return( Math.floor(Math.random() * (max - min + 1) ) + min );
}

//Then
if (message.content.startsWith("<lottery")){
    const args = message.content.slice("<lottery".length).split(" ");
    // args is the arguments aka input passed by the user
    if(!args.length){
        //not enough input
        return(message.reply("Not enough input"));
    }
    if(!parseInt(args[0])){
        //Invalid input
        return(message.reply("Invalid input - Give a number input")
    }
    let Winner = RandomInt(1, parseInt(args[0]));
    let emb = new Discord.MessageEmbed()
        //put the title and others
        .setDescription(`The winning number is ${Winner}. Congratulations`)
        //The footer and rest
    message.channel.send(emb);
}

这应该工作

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM