type LockableInteraction = { user: { id: string }; customId: string; deferUpdate(): Promise; }; const _processing = new Set(); export async function withInteractionLock( interaction: LockableInteraction, fn: () => Promise ): Promise { const key = `${interaction.user.id}:${interaction.customId}`; if (_processing.has(key)) { return null; } _processing.add(key); await interaction.deferUpdate(); try { return await fn(); } finally { _processing.delete(key); } } export const InteractionLock = { with: withInteractionLock, clear: () => _processing.clear(), // useful for testing };