MCPcopy
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Moderation/dm.js:34–108  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

32 category: "Moderation",
33
34 async execute(interaction, config, client) {
35 const deferSuccess = await InteractionHelper.safeDefer(interaction);
36 if (!deferSuccess) {
37 logger.warn(`DM interaction defer failed`, {
38 userId: interaction.user.id,
39 guildId: interaction.guildId,
40 commandName: 'dm'
41 });
42 return;
43 }
44
45 const targetUser = interaction.options.getUser("user");
46 const message = interaction.options.getString("message");
47 const anonymous = interaction.options.getBoolean("anonymous") || false;
48
49 try {
50
51 if (message.length > 2000) {
52 return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'Messages must be under 2000 characters.' });
53 }
54
55 if (targetUser.bot) {
56 return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: 'You cannot send DMs to bot accounts.' });
57 }
58
59 const sanitized = sanitizeMarkdown(message);
60
61 const dmChannel = await targetUser.createDM();
62
63 await dmChannel.send({
64 embeds: [
65 successEmbed(
66 anonymous ? "Message from the Staff Team" : `Message from ${interaction.user.tag}`,
67 sanitized
68 ).setFooter({
69 text: `You cannot reply to this message. | Logger ID: ${interaction.id}`
70 })
71 ]
72 });
73
74 await logEvent({
75 client: interaction.client,
76 guild: interaction.guild,
77 event: {
78 action: "DM Sent",
79 target: `${targetUser.tag} (${targetUser.id})`,
80 executor: `${interaction.user.tag} (${interaction.user.id})`,
81 reason: `Anonymous: ${anonymous ? 'Yes' : 'No'}`,
82 metadata: {
83 userId: targetUser.id,
84 moderatorId: interaction.user.id,
85 anonymous,
86 messageLength: sanitized.length
87 }
88 }
89 });
90
91 return await InteractionHelper.safeEditReply(interaction, {

Callers

nothing calls this directly

Calls 6

sanitizeMarkdownFunction · 0.90
successEmbedFunction · 0.90
logEventFunction · 0.90
replyUserErrorFunction · 0.85
safeDeferMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected