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 SendCommand extends BaseCommand { |
13 |
|
|
supportsInteractions: boolean = true; |
14 |
|
|
|
15 |
|
|
constructor() { |
16 |
|
|
super('send', 'moderation', []); |
17 |
|
|
} |
18 |
|
|
|
19 |
|
|
async run(client: DiscordClient, msg: Message | CommandInteraction, options: CommandOptions | InteractionOptions) { |
20 |
|
|
if (!options.isInteraction && typeof options.args[1] === 'undefined') { |
21 |
|
|
await msg.reply({ |
22 |
|
|
embeds: [ |
23 |
|
|
new MessageEmbed() |
24 |
|
|
.setColor('#f14a60') |
25 |
|
|
.setDescription(`This command requires at least two arguments.`) |
26 |
|
|
] |
27 |
|
|
}); |
28 |
|
|
|
29 |
|
|
return; |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
let content: string; |
33 |
|
|
let member: GuildMember | undefined | null; |
34 |
|
|
|
35 |
|
|
if (options.isInteraction) { |
36 |
|
|
member = await <GuildMember> options.options.getMember('member'); |
37 |
|
|
content = await <string> options.options.getString('content'); |
38 |
|
|
} |
39 |
|
|
else { |
40 |
|
|
member = await getMember(msg as Message, options); |
41 |
|
|
|
42 |
|
|
if (!member) { |
43 |
|
|
await msg.reply({ |
44 |
|
|
embeds: [ |
45 |
|
|
new MessageEmbed() |
46 |
|
|
.setColor('#f14a60') |
47 |
|
|
.setDescription(`Invalid user given.`) |
48 |
|
|
] |
49 |
|
|
}); |
50 |
|
|
|
51 |
|
|
return; |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
options.args.shift(); |
55 |
|
|
content = await options.args.join(' '); |
56 |
|
|
} |
57 |
|
|
|
58 |
|
|
try { |
59 |
|
|
await member.send({ |
60 |
|
|
content |
61 |
|
|
}); |
62 |
|
|
|
63 |
|
|
if (options.isInteraction) { |
64 |
|
|
const emoji = await fetchEmoji('check'); |
65 |
|
|
|
66 |
|
|
console.log(emoji); |
67 |
|
|
|
68 |
|
|
await msg.reply({ |
69 |
|
|
content: emoji!.toString() + " Message sent!", |
70 |
|
|
ephemeral: true |
71 |
|
|
}); |
72 |
|
|
} |
73 |
|
|
else { |
74 |
|
|
await (msg as Message).react(await fetchEmoji('check') as EmojiIdentifierResolvable); |
75 |
|
|
} |
76 |
|
|
} |
77 |
|
|
catch (e) { |
78 |
|
|
console.log(e); |
79 |
|
|
|
80 |
|
|
await msg.reply({ |
81 |
|
|
embeds: [ |
82 |
|
|
new MessageEmbed() |
83 |
|
|
.setColor('#f14a60') |
84 |
|
|
.setDescription(`Failed to send message. Maybe missing permissions or the user has disabled DMs?`) |
85 |
|
|
], |
86 |
|
|
ephemeral: true |
87 |
|
|
}); |
88 |
|
|
|
89 |
|
|
return; |
90 |
|
|
} |
91 |
|
|
} |
92 |
|
|
} |