MCPcopy Index your code
hub / github.com/codebymitch/TitanBot / execute

Function execute

src/commands/Moderation/warn.js:28–129  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

26 category: "moderation",
27
28 async execute(interaction, config, client) {
29 const deferSuccess = await InteractionHelper.safeDefer(interaction);
30 if (!deferSuccess) {
31 logger.warn(`Warn interaction defer failed`, {
32 userId: interaction.user.id,
33 guildId: interaction.guildId,
34 commandName: 'warn'
35 });
36 return;
37 }
38
39 try {
40 if (!interaction.member.permissions.has(PermissionFlagsBits.ModerateMembers)) {
41 throw new Error("You need the `Moderate Members` permission to issue warnings.");
42 }
43
44 const target = interaction.options.getUser("target");
45 const member = interaction.options.getMember("target");
46 const reason = interaction.options.getString("reason");
47 const moderator = interaction.user;
48 const guildId = interaction.guildId;
49
50 if (!target) {
51 throw new TitanBotError(
52 'Missing target user',
53 ErrorTypes.USER_INPUT,
54 'You must specify a user to warn.',
55 { subtype: 'invalid_user' },
56 );
57 }
58
59 if (!reason) {
60 throw new TitanBotError(
61 'Missing warning reason',
62 ErrorTypes.VALIDATION,
63 'You must provide a reason for the warning.',
64 { subtype: 'missing_required' },
65 );
66 }
67
68 if (!member) {
69 throw new TitanBotError(
70 "Target not found",
71 ErrorTypes.USER_INPUT,
72 "The target user is not currently in this server."
73 );
74 }
75
76 const hierarchyCheck = ModerationService.validateHierarchy(interaction.member, member, 'warn');
77 if (!hierarchyCheck.valid) {
78 throw new TitanBotError(
79 hierarchyCheck.error,
80 ErrorTypes.PERMISSION,
81 hierarchyCheck.error
82 );
83 }
84
85 const result = await WarningService.addWarning({

Callers

nothing calls this directly

Calls 7

logModerationActionFunction · 0.90
successEmbedFunction · 0.90
handleInteractionErrorFunction · 0.90
safeDeferMethod · 0.80
validateHierarchyMethod · 0.80
addWarningMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected