Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Wrong Channel context command #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions src/commands/context/wrong-channel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}
},
};