The Discord Ticket Bot is entirely event-driven. Beyond the single text command, all bot behaviour is implemented through threeDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/astrxnomo/discord-ticket-bot-py/llms.txt
Use this file to discover all available pages before exploring further.
@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:
- Iterates over every guild in
bot.guilds, accumulating a total member count (subtracting 1 per guild to exclude the bot itself). - Calls
bot.change_presenceto set the bot’s status to Watching{members} members, where{members}is the total count computed above. - 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.
custom_id | Action |
|---|---|
Ticket | Sends a select menu with three ticket category options (Question, Help, Report) |
call_staff | Pings the staff role with a notification embed; auto-deletes after 20 seconds |
close_ticket | Sends a close-confirmation embed with Yes and No buttons in the ticket channel |
close_yes | Deletes the ticket channel and posts a log embed to id_channel_ticket_logs |
close_no | Deletes the confirmation message, leaving the ticket open |
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.
interaction.values[0] | Channel name | Welcome embed title |
|---|---|---|
question | ❔┃{username}-ticket | Question - ¡Hi {username}! |
help | 🔧┃{username}-ticket | Help - ¡Hi {username}! |
report | 🚫┃{username}-ticket | Report - ¡Hi {username}! |
- Resolves the target category (
id_category) and the staff role (id_staff_role) from the guild. - Creates a new text channel with the appropriate emoji-prefixed name under the resolved category.
- 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_emojisall set toTrue. - Staff role — same as the ticket creator, plus
manage_messages=True.
- Sends the user a confirmation message pointing to the new channel (auto-deletes after 3 seconds).
- Posts the welcome embed with a 🔐 Close ticket button and a 🔔 Call staff button inside the new channel, mentioning the ticket creator.