/[sudobot]/trunk/src/commands/utils/AnnounceCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/utils/AnnounceCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 344 - (hide annotations)
Mon Jul 29 17:29:40 2024 UTC (8 months, 2 weeks ago) by rakin
File MIME type: application/typescript
File size: 2248 byte(s)
chore: eslint autofix
1 rakin 344 import { CommandInteraction, GuildEmoji, Message, TextChannel } from 'discord.js';
2 rakin 51 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 MessageEmbed from '../../client/MessageEmbed';
7     import { fetchEmoji } from '../../utils/Emoji';
8    
9     export default class AnnounceCommand extends BaseCommand {
10     supportsInteractions = true;
11    
12     constructor() {
13     super('announce', 'utils', []);
14     }
15    
16     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
17     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
18     await msg.reply({
19     embeds: [
20     new MessageEmbed()
21     .setColor('#f14a60')
22     .setDescription(`This command requires at least one argument.`)
23     ]
24     });
25    
26     return;
27     }
28    
29     let content: string;
30    
31     if (options.isInteraction) {
32     content = <string> await options.options.getString('content');
33     }
34     else {
35     content = await options.args.join(' ');
36     }
37    
38     try {
39     const channel = await <TextChannel> msg.guild!.channels.cache.find(c => c.id === client.config.get('announcement_channel'));
40    
41     if (!channel) {
42     await msg.reply({
43     content: ":x: Channel not found"
44     });
45    
46     return;
47     }
48    
49     await channel.send({
50     content
51     });
52    
53     if (msg instanceof Message)
54     await msg.react(<GuildEmoji> (await fetchEmoji('check')));
55     else
56     await msg.reply({
57     content: (<GuildEmoji> (await fetchEmoji('check'))).toString() + " The message has been announced!",
58     ephemeral: true
59     });
60     }
61     catch(e) {
62     console.log(e);
63    
64     await msg.reply({
65     content: ":x: Failed to send message",
66     ephemeral: true
67     });
68     }
69     }
70     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26