I see the main problems with your code is that:
You did not put your all of your dice-related code into the if
-block checking if the message is the roll
command.
- This causes the bot to reply when the number "rolled" is 6 even when the command is not invoked.
You did not check whether the message came from a bot.
- It would reply multiple times since you did not check whether the message came from your bot.
Your code would look like this once you fixed all your errors:
//Dice Roll Game
bot.on('message', message => { // If theres only one parameter, you can omit brackets
// Bot Check
if(message.author.bot)return;
// Even with useless parameters to the command, it will still run
if(message.content.startsWith('!roll')) {
// Arrays are not needed
// Gives a random int from 1 - 6, (~~) floors an integer
let random = ~~(Math.random() * 6) + 1;
message.reply(`You rolled a ${ random }!`); // ES6 Template Strings
// Please use strict equality signs to prevent bugs from appearing in your code
if(random === 6){
message.reply('You win!');
}
}
});
Side Note: If you do not want a mention prepended to your bot message, please use message.channel.send
instead of message.reply
.
Discord.js Docs