(interaction, config, client)
| 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({ |
nothing calls this directly
no test coverage detected