added 'js' command

This commit is contained in:
Mestima 2023-06-15 16:47:47 +03:00
parent 2e823228af
commit b33e253ffc

36
src/commands/js/index.js Normal file
View File

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