# Command: Create Slot
@app_commands.command(name="create", description="Create a new slot")
@app_commands.describe(
    member="The member to assign the slot to",
    duration="Duration of the slot (e.g., 7d for 7 days, 2m for 2 months)",
    category="Category of the slot (e.g., category1, category2, category3)",
    slotname="Name of the slot channel"
)
async def slash_create(interaction: discord.Interaction, member: discord.Member, duration: str, category: str, slotname: str):
    await interaction.response.defer(ephemeral=True)
    
    # Check if the user is staff or the slot owner
    staff_role = interaction.guild.get_role(STAFF_ROLE_ID)
    is_staff = staff_role in interaction.user.roles

    if not is_staff and interaction.user != member:
        await interaction.followup.send("❌ You can only create slots for yourself unless you're a staff member.")
        return

    # Validate category
    category_id = get_category_by_name(category)
    if not category_id:
        await interaction.followup.send(f"❌ Invalid category. Please choose one of: {', '.join(CATEGORY_IDS.keys())}.")
        return
    category_obj = interaction.guild.get_channel(category_id)
    if not isinstance(category_obj, discord.CategoryChannel):
        await interaction.followup.send("❌ Specified category does not exist.")
        return

    # Parse duration
    try:
        time_value = int(duration[:-1])
        time_unit = duration[-1].lower()
        if time_unit == 'd':
            delta = datetime.timedelta(days=time_value)
            duration_formatted = f"{time_value} day(s)"
        elif time_unit == 'm':
            delta = datetime.timedelta(days=30 * time_value)  # Approximation
            duration_formatted = f"{time_value} month(s)"
        else:
            raise ValueError
    except (ValueError, IndexError):
        await interaction.followup.send("❌ Invalid duration format. Use like '7d' for 7 days or '2m' for 2 months.")
        return

    # Capture Date of Purchase
    date_of_purchase = datetime.datetime.utcnow()
    end_time = date_of_purchase + delta
    end_timestamp = int(end_time.timestamp())

    # Create channel with permissions
    overwrites = {
        interaction.guild.default_role: discord.PermissionOverwrite(view_channel=False),
        member: discord.PermissionOverwrite(view_channel=True, send_messages=True, mention_everyone=False)  # Default: no @here/@everyone
    }
    
    # Add staff role to overwrites if the creator is staff
    if is_staff:
        overwrites[staff_role] = discord.PermissionOverwrite(view_channel=True, send_messages=True, mention_everyone=True)
    
    try:
        channel = await interaction.guild.create_text_channel(
            name=slotname,
            category=category_obj,
            overwrites=overwrites,
            reason=f"Slot created for {member.display_name}"
        )
    except Exception as e:
        await interaction.followup.send(f"❌ Failed to create channel: {e}")
        return

    # Assign premium role to the member
    premium_role = interaction.guild.get_role(PREMIUM_ROLE_ID)
    if premium_role:
        await member.add_roles(premium_role)

    # Insert slot into MongoDB
    slot_data = {
        "userid": member.id,
        "channelid": channel.id,
        "endtime": end_time.isoformat(),  # Store as ISO format for readability
        "ping_count": 0,
        "max_pings": 5,  # Example limit, adjust as needed
        "allow_everyone": False,  # By default, @everyone/@here are not allowed
        "category": category.lower(),
        "created_by": interaction.user.id,
        "date_of_purchase": date_of_purchase.isoformat(),
        "duration": duration_formatted
    }
    await slots_collection.insert_one(slot_data)

    # Create embed with detailed information
    embed = discord.Embed(
        title="🎰 Slot Created 🎰",
        description=(
            f"- **Slot Owner:** {member.mention}\n"
            f"- **Date of Purchase:** <t:{int(date_of_purchase.timestamp())}:F>\n"
            f"- **Duration:** {duration_formatted}\n"
            f"- **Expiry Date:** <t:{end_timestamp}:F>\n"
            f"- **Slot Name:** {slotname}\n"
            f"- **Created By:** {interaction.user.mention}"
        ),
        color=EMBED_COLOR
    )
    embed.set_thumbnail(url=interaction.guild.icon.url if interaction.guild.icon else "")
    embed.set_footer(text="Slot Management System")
    
    # Add permissions details
    permissions_description = (
        f"**Permissions:**\n"
        f"> **Maximum Pings:** {slot_data['max_pings']}\n"
        f"> **@here/@everyone Allowed:** {'Yes' if slot_data['allow_everyone'] else 'No'}"
    )
    embed.add_field(name="Permissions", value=permissions_description, inline=False)
    
    await channel.send(embed=embed)

    # Optional: Send a welcome message or instructions
    welcome_embed = discord.Embed(
        title="Welcome to your Slot!",
        description=(
            "Here you can manage your slot. Use the available commands to add or remove users, renew your slot, and more.\n\n"
            f"**Note:** You can use up to {slot_data['max_pings']} pings. {'@here and @everyone mentions are enabled.' if slot_data['allow_everyone'] else '@here and @everyone mentions are disabled.'}"
        ),
        color=EMBED_COLOR
    )
    welcome_embed.set_thumbnail(url="")
    await channel.send(embed=welcome_embed)

    await interaction.followup.send(f"✅ Successfully created slot {channel.mention} for {member.mention}.")


this isnt shown as a command in my code