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

Function execute

src/commands/Moderation/timeout.js:42–123  ·  view source on GitHub ↗
(interaction, config, client)

Source from the content-addressed store, hash-verified

40 category: "moderation",
41
42 async execute(interaction, config, client) {
43 const deferSuccess = await InteractionHelper.safeDefer(interaction);
44 if (!deferSuccess) {
45 logger.warn(`Timeout interaction defer failed`, {
46 userId: interaction.user.id,
47 guildId: interaction.guildId,
48 commandName: 'timeout'
49 });
50 return;
51 }
52
53 try {
54 if (!interaction.member.permissions.has(PermissionFlagsBits.ModerateMembers)) {
55 throw new TitanBotError(
56 "User lacks permission",
57 ErrorTypes.PERMISSION,
58 "You need the `Moderate Members` permission to set a timeout."
59 );
60 }
61
62 const targetUser = interaction.options.getUser("target");
63 const member = interaction.options.getMember("target");
64 const durationMinutes = interaction.options.getInteger("duration");
65 const reason = interaction.options.getString("reason") || "No reason provided";
66
67 if (!targetUser) {
68 throw new TitanBotError(
69 'Missing target user',
70 ErrorTypes.USER_INPUT,
71 'You must specify a user to timeout.',
72 { subtype: 'invalid_user' },
73 );
74 }
75
76 if (targetUser.id === interaction.user.id) {
77 throw new TitanBotError(
78 "Cannot timeout self",
79 ErrorTypes.VALIDATION,
80 "You cannot timeout yourself."
81 );
82 }
83 if (targetUser.id === client.user.id) {
84 throw new TitanBotError(
85 "Cannot timeout bot",
86 ErrorTypes.VALIDATION,
87 "You cannot timeout the bot."
88 );
89 }
90 if (!member) {
91 throw new TitanBotError(
92 "Target not found",
93 ErrorTypes.USER_INPUT,
94 "The target user is not currently in this server."
95 );
96 }
97
98 const durationMs = durationMinutes * 60 * 1000;
99 const result = await ModerationService.timeoutUser({

Callers

nothing calls this directly

Calls 5

successEmbedFunction · 0.90
handleInteractionErrorFunction · 0.90
safeDeferMethod · 0.80
timeoutUserMethod · 0.80
safeEditReplyMethod · 0.80

Tested by

no test coverage detected