-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathwrong-channel.ts
74 lines (67 loc) · 2.13 KB
/
wrong-channel.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import {
ActionRowBuilder,
ApplicationCommandType,
ContextMenuCommandBuilder,
ModalBuilder,
PermissionFlagsBits,
TextInputBuilder,
TextInputStyle,
} from 'discord.js';
import { ContextMenuCommand } from '../../types';
/**
* Wrong channel command
* ---
* Deletes a message and sends a DM to the user telling them it's in the wrong channel
*/
export const command: ContextMenuCommand = {
data: new ContextMenuCommandBuilder()
.setName('Wrong Channel')
.setDMPermission(false)
.setDefaultMemberPermissions(PermissionFlagsBits.ManageMessages)
.setType(ApplicationCommandType.Message),
async execute(interaction) {
const { targetMessage } = interaction;
const originalMessageContent = targetMessage.content;
const modal = new ModalBuilder()
.setCustomId('wrongChannel')
.setTitle('Delete wrong channel message')
.addComponents(
new ActionRowBuilder<TextInputBuilder>().addComponents(
new TextInputBuilder()
.setCustomId('modMessageInput')
.setLabel('Message to user (not required)')
.setValue('👋 Hey there. This message would fit better in #...')
.setRequired(false)
.setStyle(TextInputStyle.Short)
)
);
await interaction.showModal(modal);
try {
const submit = await interaction.awaitModalSubmit({
time: 5 * 60 * 1000,
filter: (i) => i.user.id === interaction.user.id,
});
const modMessage = submit.fields.getTextInputValue('modMessageInput');
await Promise.all([
targetMessage.delete(),
targetMessage.author.send({
content: `
Your message has been deleted because it was posted in the wrong channel. Feel free to post it again in the correct channel.
${modMessage ? `Moderator message: \`\`\`${modMessage}\`\`\`` : ''}`,
embeds: [
{
title: 'Deleted message:',
description: originalMessageContent,
},
],
}),
submit.reply({
ephemeral: true,
content: 'Ok!',
}),
]);
} catch (err) {
console.error(err);
}
},
};