import discord
from discord.ext import commands
from discord import app_commands

intents = discord.Intents.default()
intents.messages = True
intents.guilds = True

bot = commands.Bot(command_prefix="!", intents=intents)

GUILD_ID = 1358327205570285769  # Your server ID
TICKET_CATEGORY_ID = 1376852991453298789  # Ticket category ID

whitelisted_roles = set()
whitelisted_users = set()

# Bot owner's ID (replace with the bot owner's actual ID)
BOT_OWNER_ID = 123456789012345678  # Replace this with your bot owner's Discord ID

class TicketView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

    @discord.ui.button(label="General Question", style=discord.ButtonStyle.primary, emoji="📩")
    async def general_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):
        await create_ticket(interaction, "general")

    @discord.ui.button(label="Buy Guns", style=discord.ButtonStyle.success, emoji="🔫")
    async def buy_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):
        await create_ticket(interaction, "buy-guns")

    @discord.ui.button(label="Claim Giveaways", style=discord.ButtonStyle.secondary, emoji="🎁")
    async def claim_ticket(self, interaction: discord.Interaction, button: discord.ui.Button):
        await create_ticket(interaction, "giveaways")


class TicketActionsView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=None)

    @discord.ui.button(label="Claim Ticket", style=discord.ButtonStyle.success, emoji="✅")
    async def claim_ticket_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        if interaction.user.id != BOT_OWNER_ID and (interaction.user.id not in whitelisted_users and not any(role.id in whitelisted_roles for role in interaction.user.roles)):
            await interaction.response.send_message("🚫 You do not have permission to claim this ticket.", ephemeral=True)
            return

        await interaction.channel.send(f"🔒 {interaction.user.mention} has claimed this ticket.")
        await interaction.response.send_message("✅ You have claimed this ticket!", ephemeral=True)

    @discord.ui.button(label="Close Ticket", style=discord.ButtonStyle.danger, emoji="❌")
    async def close_ticket_button(self, interaction: discord.Interaction, button: discord.ui.Button):
        if interaction.user.id != BOT_OWNER_ID and (interaction.user.id not in whitelisted_users and not any(role.id in whitelisted_roles for role in interaction.user.roles)):
            await interaction.response.send_message("🚫 You do not have permission to close this ticket.", ephemeral=True)
            return

        await interaction.response.send_message("✅ Ticket will be closed.", ephemeral=True)
        await interaction.channel.delete()


async def create_ticket(interaction: discord.Interaction, reason: str):
    guild = interaction.guild
    category = discord.utils.get(guild.categories, id=TICKET_CATEGORY_ID)

    overwrites = {
        guild.default_role: discord.PermissionOverwrite(view_channel=False),
        interaction.user: discord.PermissionOverwrite(view_channel=True, send_messages=True, read_message_history=True)
    }

    # Add whitelisted roles and users to view the ticket
    for role_id in whitelisted_roles:
        role = guild.get_role(role_id)
        if role:
            overwrites[role] = discord.PermissionOverwrite(view_channel=True, send_messages=True, read_message_history=True)

    for user_id in whitelisted_users:
        user = guild.get_member(user_id)
        if user:
            overwrites[user] = discord.PermissionOverwrite(view_channel=True, send_messages=True, read_message_history=True)

    channel = await guild.create_text_channel(
        name=f"ticket-{interaction.user.name}-{reason}",
        category=category,
        overwrites=overwrites,
        reason=f"Ticket for {reason}"
    )

    await channel.send(f"👋 Hello {interaction.user.mention}, support will be with you shortly!\nReason: `{reason}`")
    await channel.send("🔧 Staff, use the buttons below to manage this ticket.", view=TicketActionsView())
    await interaction.response.send_message(f"✅ Ticket created: {channel.mention}", ephemeral=True)


@bot.event
async def on_ready():
    print(f"✅ Bot ready: {bot.user}")
    try:
        synced = await bot.tree.sync(guild=discord.Object(id=GUILD_ID))
        print(f"🔁 Synced {len(synced)} slash commands.")
    except Exception as e:
        print(f"⚠️ Error syncing commands: {e}")


@bot.tree.command(name="setup_ticket", description="Send the ticket panel", guild=discord.Object(id=GUILD_ID))
async def setup_ticket(interaction: discord.Interaction):
    embed = discord.Embed(title="🎟️ Ticket Panel", description="Select a reason to open a ticket:", color=0x2F3136)
    embed.set_image(url="https://[Log in to view URL]")
    embed.set_footer(text="Powered by Armed Shop")

    await interaction.channel.send(embed=embed, view=TicketView())
    await interaction.response.send_message("✅ Ticket panel sent.", ephemeral=True)


@bot.tree.command(name="close", description="Close the ticket", guild=discord.Object(id=GUILD_ID))
async def close_ticket_cmd(interaction: discord.Interaction):
    if interaction.user.id != BOT_OWNER_ID and (interaction.user.id not in whitelisted_users and not any(role.id in whitelisted_roles for role in interaction.user.roles)):
        await interaction.response.send_message("🚫 You do not have permission to close tickets.", ephemeral=True)
        return

    if interaction.channel.category.id != TICKET_CATEGORY_ID:
        await interaction.response.send_message("❌ Not a valid ticket channel.", ephemeral=True)
        return

    await interaction.response.send_message("✅ Ticket closed.", ephemeral=True)
    await interaction.channel.delete()


@bot.tree.command(name="claim", description="Claim the ticket", guild=discord.Object(id=GUILD_ID))
async def claim_ticket_cmd(interaction: discord.Interaction):
    if interaction.user.id != BOT_OWNER_ID and (interaction.user.id not in whitelisted_users and not any(role.id in whitelisted_roles for role in interaction.user.roles)):
        await interaction.response.send_message("🚫 You do not have permission to claim tickets.", ephemeral=True)
        return

    if interaction.channel.category.id != TICKET_CATEGORY_ID:
        await interaction.response.send_message("❌ Not a valid ticket channel.", ephemeral=True)
        return

    await interaction.channel.send(f"🔒 {interaction.user.mention} has claimed this ticket.")
    await interaction.response.send_message("✅ You have claimed this ticket!", ephemeral=True)


@bot.tree.command(name="whitelist", description="Whitelist a role or user", guild=discord.Object(id=GUILD_ID))
async def whitelist_cmd(interaction: discord.Interaction, user: discord.Member = None, role: discord.Role = None):
    if interaction.user.id != BOT_OWNER_ID and not interaction.user.guild_permissions.administrator:
        await interaction.response.send_message("🚫 Only the bot owner or admins can use this command.", ephemeral=True)
        return

    if user:
        whitelisted_users.add(user.id)
        await interaction.response.send_message(f"✅ Whitelisted user: {user.mention}", ephemeral=True)

    if role:
        whitelisted_roles.add(role.id)
        await interaction.response.send_message(f"✅ Whitelisted role: `{role.name}`", ephemeral=True)

    if not user and not role:
        await interaction.response.send_message("❌ Please provide a user or role to whitelist.", ephemeral=True)


bot.run("MTM3NTEwNTIwNjU2MzUwODMzNA.Gd7hW4.VG0q-2UXtpVoxsq9Sqt6Ayuvw05uTZtmhhg6_Y")

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: