Bhai Apna

"Build a Discord bot that sends a fully customizable V2 embed featuring an image, thumbnail, custom text, custom server emojis, and a separator. Include a persistent 'Order' button that, when clicked, opens a ticket system. This system must prompt the user to select a payment method, display an order review with the service, item, price, and payment method, and finally provide a 'Confirm Order' button to open a private ticket channel

Kodari AI
KodariOct 31 at 5:17 am 1
EmbedTicketBot
A Discord bot that sends a customizable V2 embed with image, thumbnail, custom text, server emojis, and a separator. Includes a persistent Order button triggering a ticket flow: payment method selection, order review showing service, item, price, and payment method, then a Confirm Order button that opens a private ticket channel for the user.
  1. Create the discord.py bot with a customizable Components V2 order panel and persistent Order button.

  2. Add the payment selection, order review, and private ticket-channel flow.

  3. Add editable configuration, dependency, and .env template files.

Created the bot with a customizable Components V2 order panel, persistent Order button, payment-method selector, order review, and private ticket channel flow.

Edit config.json to set the panel text, emoji, image and thumbnail URLs, separator, service, item, price, payment methods, and staff role ID. Replace the placeholder in .env with your bot token, install dependencies with pip install -r requirements.txt, then run python main.py.

The bot uses no privileged intents. Grant it Manage Channels, View Channels, and Send Messages; server members with Manage Server can post the panel using /post_order.

Kodari can make mistakes. Review important code before using.
Files
config.json
main.py
requirements.txt
Code
3 284
main.py
import json
import logging
import os
import re
from pathlib import Path

import discord
from discord import app_commands
from discord.ext import commands
from dotenv import load_dotenv


logging.basicConfig(
    level=logging.INFO,
    format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
logger = logging.getLogger("order-bot")

load_dotenv()
CONFIG = json.loads(Path("config.json").read_text(encoding="utf-8"))
ORDER = CONFIG["order"]
PANEL = CONFIG["panel"]


def configured_color() -> discord.Colour:
    return discord.Colour(int(PANEL.get("accent_color", 5793266)))


class PaymentSelectionView(discord.ui.View):
    def __init__(self):
        super().__init__(timeout=300)
        self.add_item(PaymentMethodSelect())


class PaymentMethodSelect(discord.ui.Select):
    def __init__(self):
        methods = ORDER["payment_methods"][:25]
        options = [discord.SelectOption(label=method[:100], value=method) for method in methods]
        super().__init__(
            placeholder="Choose a payment method",
            min_values=1,
            max_values=1,
            options=options,
        )

    async def callback(self, interaction: discord.Interaction) -> None:
        payment_method = self.values[0]
        embed = discord.Embed(title="Order review", color=configured_color())
        embed.add_field(name="Service", value=ORDER["service"], inline=True)
        embed.add_field(name="Item", value=ORDER["item"], inline=True)
        embed.add_field(name="Price", value=ORDER["price"], inline=True)
        embed.add_field(name="Payment method", value=payment_method, inline=False)
        await interaction.response.edit_message(
            content="Review your order, then confirm to open a private ticket.",
            embed=embed,
            view=OrderReviewView(payment_method),
        )


class OrderReviewView(discord.ui.View):
    def __init__(self, payment_method: str):
        super().__init__(timeout=300)
        self.payment_method = payment_method
        self.confirmed = False

    @discord.ui.button(label="Confirm Order", style=discord.ButtonStyle.success)
    async def confirm_order(
        self,
        interaction: discord.Interaction,
        button: discord.ui.Button,
    ) -> None:
        if self.confirmed:
            await interaction.response.send_message("This order is already being processed.", ephemeral=True)
            return
        if interaction.guild is None:
            await interaction.response.send_message("Orders can only be confirmed in a server.", ephemeral=True)
            return

        self.confirmed = True
        await interaction.response.edit_message(
            content="Creating your private order ticket…",
            embed=None,
            view=None,
        )

        guild = interaction.guild
        overwrites = {
            guild.default_role: discord.PermissionOverwrite(view_channel=False),
            interaction.user: discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
                attach_files=True,
                embed_links=True,
            ),
        }
        if guild.me is not None:
            overwrites[guild.me] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                manage_channels=True,
                read_message_history=True,
            )

        staff_role_id = int(CONFIG.get("staff_role_id", 0))
        if staff_role_id:
            staff_role = guild.get_role(staff_role_id)
            if staff_role is None:
                await interaction.followup.send(
                    "The configured staff role was not found in this server. Please contact an administrator.",
                    ephemeral=True,
                )
                return
            overwrites[staff_role] = discord.PermissionOverwrite(
                view_channel=True,
                send_messages=True,
                read_message_history=True,
            )

        username = re.sub(r"[^a-z0-9-]", "-", interaction.user.name.lower()).strip("-")[:16] or "customer"
        channel_name = f"order-{username}-{str(interaction.id)[-6:]}"
        topic = f"Order by {interaction.user.id} | {ORDER['service']} | {ORDER['item']}"

        try:
            ticket = await guild.create_text_channel(
                name=channel_name,
                overwrites=overwrites,
                topic=topic[:1024],
                reason=f"Order ticket for {interaction.user} ({interaction.user.id})",
            )
            await ticket.send(
                content=f"{interaction.user.mention} Your order ticket is open. A staff member will assist you here.",
                embed=discord.Embed(
                    title="Order details",
                    color=configured_color(),
                    description=(
                        f"**Service:** {ORDER['service']}\n"
                        f"**Item:** {ORDER['item']}\n"
                        f"**Price:** {ORDER['price']}\n"
                        f"**Payment method:** {self.payment_method}"
                    ),
                ),
            )
        except discord.Forbidden:
            logger.exception("Discord denied creation of an order ticket")
            await interaction.followup.send(
                "I couldn't create the ticket. Please ask an administrator to grant me Manage Channels and permission to send messages.",
                ephemeral=True,
            )
            return
        except discord.HTTPException:
            logger.exception("Discord returned an error while creating an order ticket")
            await interaction.followup.send(
                "Discord couldn't create the ticket right now. Please try again later.",
                ephemeral=True,
            )
            return

        await interaction.followup.send(f"Your private order ticket is ready: {ticket.mention}", ephemeral=True)


class OrderButton(discord.ui.Button):
    def __init__(self):
        super().__init__(
            label="Order",
            style=discord.ButtonStyle.primary,
            custom_id="order_panel:open",
        )

    async def callback(self, interaction: discord.Interaction) -> None:
        await interaction.response.send_message(
            "Select your payment method to review this order:",
            view=PaymentSelectionView(),
            ephemeral=True,
        )


class OrderPanelView(discord.ui.LayoutView):
    def __init__(self):
        super().__init__(timeout=None)
        container = discord.ui.Container(accent_colour=configured_color())
        panel_text = f"## {PANEL['title']}\n{PANEL.get('emoji', '')}\n{PANEL['description']}"

        thumbnail_url = PANEL.get("thumbnail_url", "").strip()
        if thumbnail_url:
            container.add_item(
                discord.ui.Section(
                    discord.ui.TextDisplay(panel_text),
                    accessory=discord.ui.Thumbnail(thumbnail_url),
                )
            )
        else:
            container.add_item(discord.ui.TextDisplay(panel_text))

        if PANEL.get("separator", True):
            container.add_item(discord.ui.Separator())

        image_url = PANEL.get("image_url", "").strip()
        if image_url:
            container.add_item(