/[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 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 2869 byte(s)
Release version 2.0
1 rakin 51 import { BanOptions, CommandInteraction, EmojiIdentifierResolvable, GuildMember, Interaction, Message, TextChannel, User } 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 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    
51     try {
52     await channel.send({
53     content
54     });
55    
56     if (options.isInteraction) {
57     const emoji = await fetchEmoji('check');
58    
59     console.log(emoji);
60    
61     await msg.reply({
62     content: emoji!.toString() + " Message sent!",
63     ephemeral: true
64     });
65     }
66     else {
67     await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable);
68     }
69     }
70     catch (e) {
71     console.log(e);
72    
73     await msg.reply({
74     embeds: [
75     new MessageEmbed()
76     .setColor('#f14a60')
77     .setDescription(`Failed to send message. Maybe missing permissions?`)
78     ],
79     ephemeral: true
80     });
81    
82     return;
83     }
84     }
85     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26