/[sudobot]/trunk/src/commands/settings/EvalCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/settings/EvalCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (show annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1485 byte(s)
chore: eslint autofix
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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26