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

Annotation of /trunk/src/commands/automation/EmbedBuildCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 254 - (hide annotations)
Mon Jul 29 17:29:13 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2251 byte(s)
fix: embed builders not setting custom colors
1 rakin 251 import { ColorResolvable, CommandInteraction, Message, Util } from 'discord.js';
2     import BaseCommand from '../../utils/structures/BaseCommand';
3     import DiscordClient from '../../client/Client';
4     import InteractionOptions from '../../types/InteractionOptions';
5     import MessageEmbed from '../../client/MessageEmbed';
6     import CommandOptions from '../../types/CommandOptions';
7     import { emoji, fetchEmoji } from '../../utils/Emoji';
8    
9     export default class EmbedBuildCommand extends BaseCommand {
10     supportsInteractions: boolean = false;
11    
12     constructor() {
13     super('embed__build', 'automation', []);
14     }
15    
16     async run(client: DiscordClient, message: CommandInteraction | Message, options: InteractionOptions | CommandOptions) {
17     if (!options.isInteraction && options.args[0] === undefined) {
18     await message.reply(`${emoji('error')} No embed schema provided.`);
19     return;
20     }
21    
22     try {
23 rakin 253 const embedData = JSON.parse((options.isInteraction ? options.options.getString('json_schema')! : options.args.join(' ')).replace(/^embed\:/, ''));
24 rakin 251
25     if (!embedData) {
26     throw new Error('Parse Error');
27     }
28    
29     try {
30     const embed = new MessageEmbed(embedData);
31 rakin 254
32     if (embedData.color) {
33     try {
34     embed.setColor(embedData.color);
35     }
36     catch (e) {
37     console.log(e);
38     }
39     }
40 rakin 251
41     await message.channel?.send({
42     embeds: [embed]
43     });
44    
45     if (message instanceof CommandInteraction)
46     await message.reply({ content: 'Message sent.', ephemeral: true });
47     else
48     message.react((await fetchEmoji('check'))!).catch(console.error);
49     }
50     catch (e) {
51     console.log(e);
52     message.reply({ content: 'Invalid options given.', ephemeral: true });
53     }
54     }
55     catch (e) {
56     console.log(e);
57     message.reply({ content: 'Invalid embed JSON schema given.', ephemeral: true });
58     return;
59     }
60     }
61     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26