Exec Command

This commit is contained in:
Dragon Fire
2020-09-14 10:07:42 -04:00
parent 7f457c33c9
commit 12925a9b15
3 changed files with 38 additions and 2 deletions
+35
View File
@@ -0,0 +1,35 @@
const Command = require('../../structures/Command');
const { promisify } = require('util');
const exec = promisify(require('child_process').exec);
module.exports = class ExecCommand extends Command {
constructor(client) {
super(client, {
name: 'exec',
aliases: ['execute', '$'],
group: 'util',
memberName: 'exec',
description: 'Executes a command-line application.',
ownerOnly: true,
guarded: true,
args: [
{
key: 'command',
prompt: 'What command do you want to execute?',
type: 'string'
}
]
});
}
async run(msg, { command }) {
const results = await this.exec(command);
return msg.code('sh', results);
}
async exec(command) {
const { stdout, stderr } = await exec(command);
if (stderr) return stderr.trim();
return stdout.trim();
}
};