Math command is back again

This commit is contained in:
Daniel Odendahl Jr
2017-12-05 17:28:59 +00:00
parent 2558256c0d
commit 8cfdf56c93
2 changed files with 32 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
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.');
}
}
};