/[sudobot]/trunk/src/commands/automation/EmbedCommand.ts
ViewVC logotype

Contents of /trunk/src/commands/automation/EmbedCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 249 - (show annotations)
Mon Jul 29 17:29:12 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1670 byte(s)
feat: make subcommands of embed command (#57)
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 EmbedCommand extends BaseCommand {
9 supportsInteractions: boolean = true;
10 supportsLegacy = false;
11 subcommands = ['send', 'schema', 'build'];
12
13 constructor() {
14 super('embed', 'settings', []);
15 }
16
17 async run(client: DiscordClient, message: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
18 if (!options.isInteraction && options.args[0] === undefined) {
19 await message.reply(`${emoji('error')} No subcommand provided.`);
20 return;
21 }
22
23 if (!options.isInteraction && (options.args[0] === 'send' || options.args[0] === 'schema')) {
24 await message.reply(`${emoji('error')} This command can not be used in legacy mode. Use slash commands instead.`);
25 return;
26 }
27
28 if (!options.isInteraction && !this.subcommands.includes(options.args[0])) {
29 await message.reply(`${emoji('error')} Invalid subcommand provided. Must be one of ${this.subcommands.map(c => `\`${c}\``)}.`);
30 return;
31 }
32
33 const subcommand = options.isInteraction ? options.options.getSubcommand() : options.args[0];
34
35 const command = client.commands.get('embed__' + subcommand);
36
37 if (command) {
38 await command.execute(client, message, options);
39 }
40 }
41 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26