(interaction, config, client)
| 15 | category: "moderation", |
| 16 | |
| 17 | async execute(interaction, config, client) { |
| 18 | const deferSuccess = await InteractionHelper.safeDefer(interaction); |
| 19 | if (!deferSuccess) { |
| 20 | logger.warn(`Lock interaction defer failed`, { |
| 21 | userId: interaction.user.id, |
| 22 | guildId: interaction.guildId, |
| 23 | commandName: 'lock' |
| 24 | }); |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | if (!interaction.member.permissions.has(PermissionFlagsBits.ManageChannels)) |
| 29 | return await replyUserError(interaction, { type: ErrorTypes.PERMISSION, message: 'You need the `Manage Channels` permission to lock channels.' }); |
| 30 | |
| 31 | const channel = interaction.channel; |
| 32 | const everyoneRole = interaction.guild.roles.everyone; |
| 33 | |
| 34 | try { |
| 35 | const currentPermissions = channel.permissionsFor(everyoneRole); |
| 36 | if (currentPermissions.has(PermissionFlagsBits.SendMessages) === false) { |
| 37 | return await replyUserError(interaction, { type: ErrorTypes.UNKNOWN, message: '${channel} is already locked.' }); |
| 38 | } |
| 39 | |
| 40 | await channel.permissionOverwrites.edit( |
| 41 | everyoneRole, |
| 42 | { SendMessages: false }, |
| 43 | { type: 0, reason: `Channel locked by ${interaction.user.tag}` }, |
| 44 | ); |
| 45 | |
| 46 | const lockEmbed = createEmbed( |
| 47 | "🔒 Channel Locked (Action Log)", |
| 48 | `${channel} has been locked down by ${interaction.user}.`, |
| 49 | ) |
| 50 | .setColor(getColor('moderation')) |
| 51 | .addFields( |
| 52 | { name: "Channel", value: channel.toString(), inline: true }, |
| 53 | { |
| 54 | name: "Moderator", |
| 55 | value: `${interaction.user.tag} (${interaction.user.id})`, |
| 56 | inline: true, |
| 57 | }, |
| 58 | ); |
| 59 | |
| 60 | await logEvent({ |
| 61 | client, |
| 62 | guild: interaction.guild, |
| 63 | event: { |
| 64 | action: "Channel Locked", |
| 65 | target: channel.toString(), |
| 66 | executor: `${interaction.user.tag} (${interaction.user.id})`, |
| 67 | metadata: { |
| 68 | channelId: channel.id, |
| 69 | category: channel.parent?.name || 'None', |
| 70 | moderatorId: interaction.user.id |
| 71 | } |
| 72 | } |
| 73 | }); |
| 74 |
nothing calls this directly
no test coverage detected