Skip to content

Commit

Permalink
Roll dice command (#136)
Browse files Browse the repository at this point in the history
* Create rollDice.ts

* Update rollDice.ts

* Update rollDice.ts

* Update rollDice.ts

* Update rollDice.ts

* Update rollDice.ts
  • Loading branch information
EdwinYi-JanYang authored Jan 29, 2022
1 parent 6b3edf9 commit be89d19
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/commands/fun/rollDice.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Message } from 'discord.js';
import { CommandoClient, CommandoMessage } from 'discord.js-commando';
import { BaseCommand } from '../../utils/commands';

class RollDiceCommand extends BaseCommand {
constructor(client: CommandoClient) {
super(client, {
name: 'roll-dice',
aliases: ['rd', 'roll', 'rolldice', 'dice-roll', 'diceroll', 'dice'],
group: 'fun',
args: [
{
default: 6,
key: 'sides',
prompt: 'enter the number of sides of the dice',
type: 'integer'
}
],
memberName: 'dice-coin',
description: 'Roll a dice!',
examples: [`${client.commandPrefix}dice-roll`]
});
}

getRandomInt(max: number): number {
return Math.floor(Math.random() * max) + 1;
}

async onRun(message: CommandoMessage, args: { sides: number }): Promise<Message> {
const { sides } = args;
if (sides <= 0) {
return message.reply(`I cannot compute ` + sides + ' sides!');
}
if (sides > 1000000) {
return message.reply(`that's too many sides!`);
}
const diceFace = this.getRandomInt(sides);
return message.reply(`you rolled a ` + diceFace + `!`);
}
}

export default RollDiceCommand;

0 comments on commit be89d19

Please sign in to comment.