-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
36 lines (28 loc) · 938 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const {prefix, token} = require('./config.json');
const Discord = require('discord.js');
const client = new Discord.Client();
function roll(number) {
return Math.floor(Math.random() * (number-1+1)+1);
}
function isValidDie(number) {
return number % 2 === 0 && (number > 3 && number < 21) || number === 100;
}
client.once('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (command === 'rolld'){
var die = parseInt(args[0]);
args.shift();
var reason = args.join(' ');
if (isValidDie(die)) {
message.channel.send(`${message.author.username} rolled a: ${roll(die)} for ${reason}`);
} else {
message.channel.send('Invalid die!');
}
}
});
client.login(token);