mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-09 18:39:35 +02:00
Add back math command
This commit is contained in:
@@ -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: ['calculator', 'calc'],
|
||||
group: 'num-edit',
|
||||
memberName: 'math',
|
||||
description: 'Evaluates math expressions.',
|
||||
args: [
|
||||
{
|
||||
key: 'expression',
|
||||
prompt: 'What expression would you like to evaluate?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { expression }) {
|
||||
try {
|
||||
const answer = math.eval(expression).toString();
|
||||
return msg.say(answer).catch(() => msg.reply('Invalid expression.'));
|
||||
} catch (err) {
|
||||
return msg.reply('Invalid expression.');
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user