1 |
import { CommandInteraction, Message } from 'discord.js'; |
2 |
import BaseCommand from '../../utils/structures/BaseCommand'; |
3 |
import DiscordClient from '../../client/Client'; |
4 |
import CommandOptions from '../../types/CommandOptions'; |
5 |
import InteractionOptions from '../../types/InteractionOptions'; |
6 |
import { emoji } from '../../utils/Emoji'; |
7 |
|
8 |
export default class EvalCommand extends BaseCommand { |
9 |
supportsInteractions: boolean = true; |
10 |
ownerOnly = true; |
11 |
|
12 |
constructor() { |
13 |
super('eval', 'settings', []); |
14 |
} |
15 |
|
16 |
async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
17 |
if (!options.isInteraction && options.args[0] === undefined) { |
18 |
await message.reply({ |
19 |
content: emoji('error') + " Please enter the raw code that you want to execute.", |
20 |
ephemeral: true |
21 |
}); |
22 |
|
23 |
return; |
24 |
} |
25 |
|
26 |
const code = options.isInteraction ? options.options.getString('code') : options.args.join(' '); |
27 |
|
28 |
try { |
29 |
const result = eval(code!); |
30 |
|
31 |
await message.reply({ |
32 |
content: `${emoji('check')} **Execution Result:**\n\n\`\`\`js\n${result}\`\`\``, |
33 |
ephemeral: true |
34 |
}); |
35 |
} |
36 |
catch (e) { |
37 |
await message.reply({ |
38 |
content: `${emoji('error')} **Error Occurred!**\n\n\`\`\`\n${e}\`\`\``, |
39 |
ephemeral: true |
40 |
}); |
41 |
} |
42 |
} |
43 |
} |