Skip to content

Commit

Permalink
🎲 Add roll command
Browse files Browse the repository at this point in the history
  • Loading branch information
wiki-Bird committed Aug 26, 2023
1 parent 9570573 commit f5611bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
28 changes: 28 additions & 0 deletions src/commands/roll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import Command from '../types/Command';
import { CommandInteraction } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';

const roll: Command = {
data: new SlashCommandBuilder()
.setName('roll')
.addNumberOption(option =>
option.setName("max")
.setDescription("The maximum number to roll, 1 to this number (inclusive)")
.setRequired(true)
)
.setDescription('Roll a die or flip a coin.'),

execute: async function (interaction: CommandInteraction<'cached' | 'raw'>): Promise<void> {

const maxNumber = interaction.options.getNumber("max") ?? 2;
if (isNaN(maxNumber)) {
await interaction.reply({ content: `Invalid number.`, ephemeral: true });
return;
}

const randomNumber = Math.floor(Math.random() * maxNumber) + 1;
await interaction.reply({ content: `${interaction.user} rolled a ${randomNumber}!` });
}
}

export default roll;
2 changes: 1 addition & 1 deletion src/commands/rule.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,4 @@ const rule: Command = {
}
}

export default rule;
export default rule;

0 comments on commit f5611bb

Please sign in to comment.