/[sudobot]/trunk/src/commands/moderation/EchoCommand.ts
ViewVC logotype

Annotation of /trunk/src/commands/moderation/EchoCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 206 - (hide annotations)
Mon Jul 29 17:29:01 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 3134 byte(s)
refactor: commands requires special permissions
1 rakin 206 import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, Permissions, TextChannel, User } 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 getUser from '../../utils/getUser';
8     import getMember from '../../utils/getMember';
9     import History from '../../automod/History';
10     import { fetchEmoji } from '../../utils/Emoji';
11    
12     export default class EchoCommand extends BaseCommand {
13     supportsInteractions: boolean = true;
14 rakin 206 permissions = [Permissions.FLAGS.MANAGE_MESSAGES];
15 rakin 51
16     constructor() {
17     super('echo', 'moderation', []);
18     }
19    
20     async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) {
21     if (!options.isInteraction && typeof options.args[0] === 'undefined') {
22     await msg.reply({
23     embeds: [
24     new MessageEmbed()
25     .setColor('#f14a60')
26     .setDescription(`This command requires at least one argument.`)
27     ]
28     });
29    
30     return;
31     }
32    
33     let content: string;
34     let channel: TextChannel = <TextChannel> msg.channel;
35    
36     if (options.isInteraction) {
37     content = await <string> options.options.getString('content');
38    
39     if (options.options.getChannel('channel')) {
40     channel = await <TextChannel> options.options.getChannel('channel');
41     }
42     }
43     else {
44     if ((msg as Message).mentions.channels.last()) {
45     channel = await <TextChannel> (msg as Message).mentions.channels.last();
46     await options.args.pop();
47     }
48    
49     content = await options.args.join(' ');
50     }
51 rakin 55
52     if (!channel.send) {
53     await msg.reply({
54     content: 'Invalid text channel.',
55     ephemeral: true
56     });
57 rakin 51
58 rakin 55 return;
59     }
60    
61 rakin 51 try {
62     await channel.send({
63     content
64     });
65    
66     if (options.isInteraction) {
67     const emoji = await fetchEmoji('check');
68    
69     console.log(emoji);
70    
71     await msg.reply({
72     content: emoji!.toString() + " Message sent!",
73     ephemeral: true
74     });
75     }
76     else {
77     await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable);
78     }
79     }
80     catch (e) {
81     console.log(e);
82    
83     await msg.reply({
84     embeds: [
85     new MessageEmbed()
86     .setColor('#f14a60')
87     .setDescription(`Failed to send message. Maybe missing permissions?`)
88     ],
89     ephemeral: true
90     });
91    
92     return;
93     }
94     }
95     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26