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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26