2021年1月25日星期一

Calculator wait for user input (Discord.js)

I am doing a Discord bot, which idea would be rather simple. It asks the user for 3 numbers, and what should be done with them (add or remove). Currently the command works when you add them all as a single line (!calc add 1 1 1) and then prints the result (1 + 1 + 1 = 3). However i want to know how to set the bot ask the number inputs as 3 different questions, instead of needing to telling them all at once.

     module.exports = {  name: 'calc',  description: "calculating",  execute(message, args){      let method = args[0];      let firstNumber = Number(args[1]);      let secondNumber = Number(args[2]);      let thirdNumber = Number(args[3]);            const operations = ['add', 'remove'];        if(!method) return message.reply('please select add or remove');        if (!args[1]) return message.reply('please state first number');        if (!args[2]) return message.reply('please state second number');        if (!args[3]) return message.reply('please state third number');        if (isNaN(firstNumber)) return message.reply('number 1 missing');        if (isNaN(secondNumber)) return message.reply('number 2 missing');        if (isNaN(thirdNumber)) return message.reply('number 3 missing');        if (method === 'add') {            let doMath = firstNumber + secondNumber + thirdNumber          message.channel.send(`${firstNumber} + ${secondNumber} + ${thirdNumber} = ${doMath}`);            if (method === 'remove') {                let doMath = firstNumber - secondNumber - thirdNumber              message.channel.send(`${firstNumber} - ${secondNumber} - ${thirdNumber} = ${doMath}`);     }    }   }  }  

To show what happens in Discord itself: calculation process add

Im myself new to coding, so things like this give me problems. Thanks already for answers.

https://stackoverflow.com/questions/65895489/calculator-wait-for-user-input-discord-js January 26, 2021 at 11:24AM

没有评论:

发表评论