(interaction, client)
| 26 | export default { |
| 27 | name: Events.InteractionCreate, |
| 28 | async execute(interaction, client) { |
| 29 | const interactionTraceContext = createInteractionTraceContext(interaction); |
| 30 | interaction.traceContext = interactionTraceContext; |
| 31 | interaction.traceId = interactionTraceContext.traceId; |
| 32 | |
| 33 | return runWithTraceContext(interactionTraceContext, async () => { |
| 34 | try { |
| 35 | InteractionHelper.patchInteractionResponses(interaction); |
| 36 | ResponseCoordinator.attach(interaction); |
| 37 | |
| 38 | if (interaction.isChatInputCommand()) { |
| 39 | try { |
| 40 | logger.info(`Command executed: /${interaction.commandName} by ${interaction.user.tag}`, { |
| 41 | event: 'interaction.command.received', |
| 42 | traceId: interactionTraceContext.traceId, |
| 43 | guildId: interaction.guildId, |
| 44 | userId: interaction.user?.id, |
| 45 | command: interaction.commandName |
| 46 | }); |
| 47 | |
| 48 | validateChatInputPayloadOrThrow(interaction, withTraceContext({ |
| 49 | type: 'command_input_validation', |
| 50 | commandName: interaction.commandName |
| 51 | }, interactionTraceContext)); |
| 52 | |
| 53 | const command = client.commands.get(interaction.commandName); |
| 54 | |
| 55 | if (!command) { |
| 56 | throw createError( |
| 57 | `No command matching ${interaction.commandName} was found.`, |
| 58 | ErrorTypes.CONFIGURATION, |
| 59 | 'Sorry, that command does not exist.', |
| 60 | withTraceContext({ commandName: interaction.commandName }, interactionTraceContext) |
| 61 | ); |
| 62 | } |
| 63 | |
| 64 | const abuseProtection = await enforceAbuseProtection(interaction, command, interaction.commandName); |
| 65 | if (!abuseProtection.allowed) { |
| 66 | const formattedCooldown = formatCooldownDuration(abuseProtection.remainingMs); |
| 67 | throw createError( |
| 68 | `Risky command cooldown active for ${interaction.commandName}`, |
| 69 | ErrorTypes.RATE_LIMIT, |
| 70 | `This command is on cooldown. Please wait ${formattedCooldown} before trying again.`, |
| 71 | withTraceContext({ |
| 72 | commandName: interaction.commandName, |
| 73 | subtype: 'command_cooldown', |
| 74 | expected: true, |
| 75 | cooldownMs: abuseProtection.remainingMs, |
| 76 | cooldownWindowMs: abuseProtection.policy?.windowMs, |
| 77 | cooldownMaxAttempts: abuseProtection.policy?.maxAttempts |
| 78 | }, interactionTraceContext) |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | let guildConfig = null; |
| 83 | if (interaction.guild) { |
| 84 | guildConfig = await getGuildConfig(client, interaction.guild.id, interactionTraceContext); |
| 85 | const accessKey = resolveSlashAccessKey(interaction); |
nothing calls this directly
no test coverage detected