选择机器人滚动多少次(Discord.js)

时间:2020-09-28 00:55:08

标签: javascript node.js discord discord.js

现在,我正在研究一个随机数生成器,就像虚拟的骰子滚子一样。我让用户输入一个数字,该漫游器会随机选择一个介于1和用户输入的数字之间的数字。我一直在尝试以一种方式让用户首先说出他们希望滚动多少次。我对如何使用已经存在的代码执行此操作感到非常困惑。

快速浏览: 我希望机器人在用户发送最大滚动次数后询问我,我希望机器人询问他们想要滚动多少次。

代码:

const Discord = require('discord.js');

const client = new Discord.Client();

function getRandomInt(max){
    return Math.floor(Math.random() * Math.floor(max));
}

const prefix = 'roll';

client.once('ready', () => {
    console.log('your bot name is online!');
    client.user.setActivity("Type 'Role Help'", {type: 3}); 
});

client.on('message', message =>{
    if(!message.content.toLowerCase().startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).trim().split(/ +/g);
    const command = args.shift().toLowerCase();

    if(command === ''){
       message.channel.send("What's the **Max** role number you want?");
       message.channel.awaitMessages(m => m.author.id == message.author.id,
        {max: 1, time: 10000}).then(collected => {
            console.log('collected :' + collected.first().content);
            if (isNaN(collected.first().content)){
                return message.channel.send("Please provide a valid number!")};
            
            var n = (getRandomInt(collected.first().content));  
            message.channel.send("You Rolled a " + (n + 1));
            }).catch(() => {
                message.channel.send("*Roll has been cancelled.*");
     
            })} else if(command === 'Help' || 'help' || 'h' || 'H'){

                message.channel.send("**How to use Roll Bot**");
                message.channel.send("*1. Type Roll to begin*");
                message.channel.send("*2. Input a number or type stop to end the roll.*");
                message.channel.send("**Have Fun!**");
        }
});

client.login(process.env.token);

0 个答案:

没有答案