Fix /cc-create command creating twice instead of waiting for confirmation

The /cc-create command was immediately creating the custom command after the modal
was submitted, instead of waiting for the user to click the "Create Command" button
in the confirmation view.

Issue: Command handler was calling create_command() service immediately after modal
submission, before user confirmed via the preview buttons.

Fix: Removed premature command creation logic from the command handler. The modal's
on_submit method already shows a preview with confirmation buttons, and the
CustomCommandCreateConfirmationView.confirm_create button handler properly creates
the command only when the user clicks "Create Command".

Flow now correctly:
1. User submits modal with command details
2. Preview displays with "Create Command" and "Cancel" buttons
3. Command is only created when user clicks "Create Command" button
4. User can cancel without creating anything

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Cal Corum 2025-11-14 08:28:45 -06:00
parent 8d6bc1c681
commit bb82e56355

View File

@ -110,67 +110,8 @@ class CustomCommandsCommands(commands.Cog):
modal = CustomCommandCreateModal()
await interaction.response.send_modal(modal)
# Wait for modal completion
await modal.wait()
if not modal.is_submitted:
return
try:
# Create the command
command = await custom_commands_service.create_command(
name=modal.result['name'], # type: ignore
content=modal.result['content'], # pyright: ignore[reportOptionalSubscript]
creator_discord_id=interaction.user.id,
creator_username=interaction.user.name,
creator_display_name=interaction.user.display_name,
tags=modal.result.get('tags')
)
# Success embed
embed = EmbedTemplate.success(
title="Custom Command Created!",
description=f"Your command `/cc {command.name}` has been created successfully."
)
embed.add_field(
name="How to use it",
value=f"Type `/cc {command.name}` to execute your command.",
inline=False
)
embed.add_field(
name="Management",
value="Use `/cc-mine` to view and manage all your commands.",
inline=False
)
# Try to get the original interaction for editing
try:
# Get the interaction that triggered the modal
original_response = await interaction.original_response()
await interaction.edit_original_response(embed=embed, view=None)
except (discord.NotFound, discord.HTTPException):
# If we can't edit the original, send a followup
await interaction.followup.send(embed=embed, ephemeral=True)
except CustomCommandExistsError:
embed = EmbedTemplate.error(
title="Command Already Exists",
description=f"A command named `{modal.result['name']}` already exists.\nTry a different name." # pyright: ignore[reportOptionalSubscript]
)
await interaction.followup.send(embed=embed, ephemeral=True)
except Exception as e:
self.logger.error("Failed to create custom command",
command_name=modal.result.get('name'), # pyright: ignore[reportOptionalMemberAccess]
user_id=interaction.user.id,
error=e)
embed = EmbedTemplate.error(
title="Creation Failed",
description="An error occurred while creating your command. Please try again."
)
await interaction.followup.send(embed=embed, ephemeral=True)
# Modal's on_submit will show preview with confirmation buttons
# The CustomCommandCreateConfirmationView handles actual command creation
@app_commands.command(name="cc-edit", description="Edit one of your custom commands")
@app_commands.describe(name="Name of the command to edit")