diff --git a/commands/utils/calcul.js b/commands/utils/calcul.js new file mode 100644 index 0000000..b59d060 --- /dev/null +++ b/commands/utils/calcul.js @@ -0,0 +1,32 @@ +const { EmbedBuilder } = require("discord.js"); + +module.exports = { + name: 'calcul', + description: 'Calcul a math problem', + emote: '🔍', + utilisation: 'calcul ', + category: 'utils', + + async execute(message, args, client) { + const problem = args.join(' '); + + if (!problem) { + return message.reply('Veuillez spécifier un problème mathématique'); + } + + let result; + try { + result = eval(problem); + } catch (error) { + return message.reply('Veuillez spécifier un problème mathématique valide'); + } + + const embed = new EmbedBuilder() + .setTitle('Calculateur de mathématiques') + .setDescription(`Calcul :\n\`\`\`${problem}\`\`\`\nRésultat :\`\`\`${result}\`\`\``) + .setFooter({ text: `Demandé par ${message.author.tag}`, iconURL: message.author.displayAvatarURL() }) + .setTimestamp(); + + message.channel.send({ embeds: [embed] }); + }, +}; \ No newline at end of file