Files
xiao/commands/number-edit/math.js
T
2017-12-05 17:28:59 +00:00

31 lines
704 B
JavaScript

const { Command } = require('discord.js-commando');
const math = require('mathjs');
module.exports = class MathCommand extends Command {
constructor(client) {
super(client, {
name: 'math',
aliases: ['mathematics', 'solve'],
group: 'number-edit',
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 = math.eval(expression).toString();
return msg.say(evaluated).catch(() => msg.say('Invalid expression.'));
} catch (err) {
return msg.say('Invalid expression.');
}
}
};