From 3b75fe165d8930bbd473c7ecb8fb5ad6bd438308 Mon Sep 17 00:00:00 2001 From: SileNce5k Date: Sat, 13 Mar 2021 04:04:02 +0100 Subject: [PATCH] Add random number command --- commands/random.js | 16 ++++++++++++++++ util/randomNumber.js | 3 +++ 2 files changed, 19 insertions(+) create mode 100644 commands/random.js create mode 100644 util/randomNumber.js diff --git a/commands/random.js b/commands/random.js new file mode 100644 index 0000000..711e692 --- /dev/null +++ b/commands/random.js @@ -0,0 +1,16 @@ +const randomNumber = require('../util/randomNumber') + +module.exports = { + name: 'random', + description: 'Returns a value between two numbers (default = 1-10)', + execute({ message, args }) { + let min = 1 + let max = 10 + if (args[0] && args[1]) { + min = parseInt(args[0]) + max = parseInt(args[1]) + } + let randNumber= randomNumber(min,max) + message.channel.send(randNumber) + } +}; \ No newline at end of file diff --git a/util/randomNumber.js b/util/randomNumber.js new file mode 100644 index 0000000..b43f3ae --- /dev/null +++ b/util/randomNumber.js @@ -0,0 +1,3 @@ +module.exports = function (min, max) { + return Math.floor(Math.random() * (max - min + 1) + min); +} \ No newline at end of file