From b33e253ffc2afd5f351e5f758e642870921459f4 Mon Sep 17 00:00:00 2001 From: Mestima Date: Thu, 15 Jun 2023 16:47:47 +0300 Subject: [PATCH] added 'js' command --- src/commands/js/index.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 src/commands/js/index.js diff --git a/src/commands/js/index.js b/src/commands/js/index.js new file mode 100644 index 0000000..ab85b4b --- /dev/null +++ b/src/commands/js/index.js @@ -0,0 +1,36 @@ +import { SlashCommandBuilder } from 'discord.js'; +import { node } from 'compile-run'; + +export default { + data: new SlashCommandBuilder() + .setName('js') + .setDescription('Execute JavaScript code.') + .addStringOption((option) => { + option.setName('code') + .setDescription('code to execute') + .setRequired(true); + return option; + }) + .addBooleanOption((option) => { + option.setName('hide') + .setDescription('hide your code') + .setRequired(false); + return option; + }), + async execute(interaction, api) { + const code = interaction.options.getString('code'); + const hide = interaction.options.getBoolean('hide'); + node.runSource(code) + .then(res => { + let payload = '```js\n' + res.stdout + '\n```'; + if (!hide) { + payload = '```js\n' + code + '\n```' + payload; + } + + interaction.reply(payload); + }) + .catch(e => { + throw e; + }); + } +};