const { SlashCommandBuilder } = require('@discordjs/builders'); module.exports = { data: new SlashCommandBuilder() .setName('roll') .setDescription('Roll the dice, seal your fate.') .addStringOption(option => option.setName('dice') .setDescription('*ex: /roll 1d6 - max 100 faces - max 15 dés') .setRequired(true) ), async execute(interaction) { const option = interaction.options.get('dice'); const regex = /^([0-9]){1,}([dD])([0-9]{1,})$/; if(!option.value.match(regex)){ await interaction.reply({content: 'Veuillez entrer le bon format - *ex: 1d6*', ephemeral: true}); return; } const args = option.value.split(/[dD]/); const num = parseInt(args[0]); const dice = parseInt(args[1]); if(num < 1 || num > 15){ await interaction.reply({content: 'Veuillez entrer un nombre de dé compris entre 1 et 15 - *ex: 1d6*', ephemeral: true}); return; } if(dice < 1 || dice > 100){ await interaction.reply({content: 'Veuillez entrer un nombre de dé compris entre 1 et 15 - *ex: 1d6*', ephemeral: true}); return; } var reply = num + " dés de " + dice + " faces lancés :\t"; var total = 0; var dices = "" for(var i = 0; i < num; i++){ var roll = 1 + Math.floor(Math.random() * (dice)); total += roll; dices += " 🎲 **" + roll + "** "; } reply += "*total de* **" + total + "**\n" + dices; await interaction.reply(reply); }, };