|
| 1 | +import type { MessageContextMenuCommandInteraction } from "discord.js"; |
| 2 | +import { |
| 3 | + ApplicationCommandType, |
| 4 | + ChannelType, |
| 5 | + ContextMenuCommandBuilder, |
| 6 | + EmbedBuilder, |
| 7 | +} from "discord.js"; |
| 8 | +import type { Command } from "./types.js"; |
| 9 | + |
| 10 | +const data = new ContextMenuCommandBuilder() |
| 11 | + .setName("Report to Moderators") |
| 12 | + .setType(ApplicationCommandType.Message); // ApplicationCommandType.Message = 3 |
| 13 | + |
| 14 | +async function execute(interaction: MessageContextMenuCommandInteraction) { |
| 15 | + const targetMessage = interaction.targetMessage; |
| 16 | + const guild = interaction.guild; |
| 17 | + const reporter = interaction.user; |
| 18 | + |
| 19 | + if (!guild) { |
| 20 | + await interaction.reply({ content: "This can only be used in a server.", ephemeral: true }); |
| 21 | + return; |
| 22 | + } |
| 23 | + |
| 24 | + try { |
| 25 | + const channelId = "1407649112228368474"; |
| 26 | + const channel = await guild.channels.fetch(channelId); |
| 27 | + if (!channel || channel.type !== ChannelType.GuildText) { |
| 28 | + await interaction.reply({ |
| 29 | + content: "Moderator channel not found or is not a text channel.", |
| 30 | + ephemeral: true, |
| 31 | + }); |
| 32 | + return; |
| 33 | + } |
| 34 | + |
| 35 | + const jumpLink = targetMessage.url; |
| 36 | + const authorTag = targetMessage.author?.tag ?? "Unknown"; |
| 37 | + const authorId = targetMessage.author?.id ?? "Unknown"; |
| 38 | + |
| 39 | + const embed = new EmbedBuilder() |
| 40 | + .setTitle("🚩 Message Report") |
| 41 | + .setColor(0xff4d4f) |
| 42 | + .setTimestamp() |
| 43 | + .setURL(jumpLink) |
| 44 | + .addFields( |
| 45 | + { name: "Reporter", value: `<@${reporter.id}>`, inline: true }, |
| 46 | + { name: "Message Link", value: `[Jump to message](${jumpLink})`, inline: true }, |
| 47 | + { name: "Message ID", value: targetMessage.id, inline: true }, |
| 48 | + { name: "Username", value: authorTag, inline: true }, |
| 49 | + { name: "User ID", value: authorId, inline: true }, |
| 50 | + { name: "Linked User", value: `<@${authorId}>`, inline: true } |
| 51 | + ); |
| 52 | + |
| 53 | + await channel.send({ embeds: [embed] }); |
| 54 | + |
| 55 | + await interaction.reply({ |
| 56 | + content: "Thanks. The message was reported to moderators.", |
| 57 | + ephemeral: true, |
| 58 | + }); |
| 59 | + } catch (error) { |
| 60 | + console.error(error); |
| 61 | + await interaction.reply({ content: "Failed to report the message.", ephemeral: true }); |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +export const reportMessage: Command<MessageContextMenuCommandInteraction> = { |
| 66 | + data, |
| 67 | + execute, |
| 68 | +}; |
0 commit comments