Haha-Yes/commands/owner/exec.js

40 lines
996 B
JavaScript
Raw Normal View History

2019-05-11 20:28:26 +02:00
const { Command } = require('discord-akairo');
const util = require('util');
const exec = util.promisify(require('child_process').exec);
class execCommand extends Command {
constructor() {
super('exec', {
aliases: ['exec'],
category: 'owner',
ownerOnly: 'true',
args: [
{
id: 'exec',
type: 'string',
match: 'rest'
}
],
description: {
content: 'execute a command on the server',
usage: '[a command on the server]',
examples: ['pm2 list']
}
});
}
async exec(message, args) {
async function update() {
2019-12-17 20:28:37 +01:00
let { stdout, stderr } = await exec(args.exec).catch(err => {
return message.channel.send(`Oh no, an error has occurred\n${err}`);
2019-05-11 20:28:26 +02:00
});
2019-12-17 20:28:37 +01:00
if (!stdout) stdout = 'Nothing';
if (!stderr) stderr = 'No error';
2019-12-17 20:26:44 +01:00
message.channel.send(`stdout: \n\`\`\`${stdout}\`\`\``, { split: true });
message.channel.send(`stderr: \n\`\`\`${stderr}\`\`\``, { split: true });
2019-05-11 20:28:26 +02:00
}
return update();
}
}
module.exports = execCommand;