Skip to main content
The Discord Ticket Bot is entirely event-driven. Beyond the single text command, all bot behaviour is implemented through three @bot.event handlers provided by discord.py and the discord_components library. on_ready handles startup, while on_button_click and on_select_option together manage the full ticket lifecycle — from opening a ticket to closing it and logging the result.

on_ready

Triggered when: the bot successfully connects to Discord and has finished loading its internal state. Behavior:
  1. Iterates over every guild in bot.guilds, accumulating a total member count (subtracting 1 per guild to exclude the bot itself).
  2. Calls bot.change_presence to set the bot’s status to Watching {members} members, where {members} is the total count computed above.
  3. Prints Ready to support ✅ to stdout.

on_button_click(interaction)

Triggered when: any button component in any guild the bot can see is clicked by a user. Routing: the handler dispatches on interaction.component.custom_id using a chain of if/elif branches.

on_select_option(interaction)

Triggered when: a user picks an option from any select menu the bot has rendered. Routing: the handler first checks interaction.component.custom_id == "menu", then branches on interaction.values[0] to determine which ticket category was selected. For each value, the handler performs the same sequence of steps:
  1. Resolves the target category (id_category) and the staff role (id_staff_role) from the guild.
  2. Creates a new text channel with the appropriate emoji-prefixed name under the resolved category.
  3. Sets three permission overrides on the new channel:
    • @everyone — send_messages=False, read_messages=False (hides the channel from non-participants).
    • Ticket creator — send_messages, read_messages, add_reactions, embed_links, attach_files, read_message_history, external_emojis all set to True.
    • Staff role — same as the ticket creator, plus manage_messages=True.
  4. Sends the user a confirmation message pointing to the new channel (auto-deletes after 3 seconds).
  5. Posts the welcome embed with a 🔐 Close ticket button and a 🔔 Call staff button inside the new channel, mentioning the ticket creator.