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; + }); + } +};