JaBa/commands/Owner/eval.js

67 lines
2 KiB
JavaScript
Raw Permalink Normal View History

2024-09-19 23:58:06 +05:00
const { SlashCommandBuilder, InteractionContextType, ApplicationIntegrationType } = require("discord.js");
const BaseCommand = require("../../base/BaseCommand");
class Eval extends BaseCommand {
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../base/Client")} client
*/
constructor(client) {
super({
command: new SlashCommandBuilder()
.setName("eval")
.setDescription(client.translate("owner/eval:DESCRIPTION"))
.setDescriptionLocalizations({
2023-07-05 00:58:06 +05:00
uk: client.translate("owner/eval:DESCRIPTION", null, "uk-UA"),
ru: client.translate("owner/eval:DESCRIPTION", null, "ru-RU"),
})
2024-09-19 23:58:06 +05:00
.setIntegrationTypes([ApplicationIntegrationType.GuildInstall, ApplicationIntegrationType.UserInstall])
2024-09-14 19:52:56 +05:00
.setContexts([InteractionContextType.BotDM, InteractionContextType.PrivateChannel, InteractionContextType.Guild])
2023-07-05 00:58:06 +05:00
.addStringOption(option =>
option
.setName("code")
.setDescription(client.translate("owner/eval:CODE"))
.setDescriptionLocalizations({
uk: client.translate("owner/eval:CODE", null, "uk-UA"),
ru: client.translate("owner/eval:CODE", null, "ru-RU"),
})
.setRequired(true),
),
dirname: __dirname,
ownerOnly: true,
});
}
/**
*
2023-11-05 16:03:23 +05:00
* @param {import("../../base/Client")} client
* @param {import("discord.js").ChatInputCommandInteraction} interaction
*/
2024-02-09 23:26:57 +05:00
async execute(client, interaction) {
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)));
2023-07-05 00:58:06 +05:00
return result
.then(output => {
if (typeof output !== "string") output = require("util").inspect(output);
if (output.includes(client.token)) output = output.replace(client.token, "T0K3N");
2023-07-05 00:58:06 +05:00
interaction.editReply({
content: "```js\n" + output + "```",
});
})
.catch(err => {
console.log(err);
err = err.toString();
if (err.includes(client.token)) err = err.replace(client.token, "T0K3N");
2023-07-05 00:58:06 +05:00
interaction.editReply({
content: "```js\n" + err + "```",
});
});
}
}
2023-07-05 00:58:06 +05:00
module.exports = Eval;