JaBa/commands/Owner/eval.js

61 lines
1.6 KiB
JavaScript
Raw Normal View History

const { SlashCommandBuilder } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Eval extends BaseCommand {
/**
*
* @param {import("../base/JaBa")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("eval")
.setDescription(client.translate("owner/eval:DESCRIPTION"))
.setDMPermission(true)
.addStringOption(option => option.setName("code")
.setDescription(client.translate("owner/eval:CODE"))
.setRequired(true)),
aliases: [],
dirname: __dirname,
ownerOnly: true,
});
}
/**
*
* @param {import("../../base/JaBa")} client
*/
async onLoad() {
//...
}
/**
*
* @param {import("../../base/JaBa")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
2022-08-09 23:48:33 +05:00
* @param {Object} data
*/
// eslint-disable-next-line no-unused-vars
async execute(client, interaction, data) {
2022-08-30 14:26:56 +05:00
await interaction.deferReply({ ephemeral: true });
const code = interaction.options.getString("code");
2022-08-09 23:48:33 +05:00
const result = new Promise(resolve => resolve(eval(code)));
2022-08-09 23:48:33 +05:00
return result.then(output => {
if (typeof output != "string") output = require("util").inspect(output, { depth: 0 });
if (output.includes(client.token)) output = output.replace(client.token, "T0K3N");
2022-08-30 14:26:56 +05:00
interaction.editReply({
content: "```js\n" + output + "```",
});
2022-08-09 23:48:33 +05:00
}).catch(err => {
console.error(err);
err = err.toString();
if (err.includes(client.token)) err = err.replace(client.token, "T0K3N");
2022-08-30 14:26:56 +05:00
interaction.editReply({
content: "```js\n" + err + "```",
});
});
}
}
module.exports = Eval;