Files
xiao/commands/edit-number/math.js
T
2020-12-15 17:36:03 -05:00

31 lines
721 B
JavaScript

const Command = require('../../structures/Command');
const { Parser } = require('expr-eval');
module.exports = class MathCommand extends Command {
constructor(client) {
super(client, {
name: 'math',
aliases: ['mathematics', 'solve'],
group: 'edit-number',
memberName: 'math',
description: 'Evaluates a math expression.',
args: [
{
key: 'expression',
prompt: 'What expression do you want to evaluate?',
type: 'string'
}
]
});
}
run(msg, { expression }) {
try {
const evaluated = Parser.evaluate(expression).toString();
return msg.reply(evaluated).catch(() => msg.reply('Invalid expression.'));
} catch {
return msg.reply('Invalid expression.');
}
}
};