Ticket Creation Flow
Relevant source files
The following files were used as context for generating this wiki page:
The Ticket Creation Flow is a core support feature of TrackerBot designed to facilitate private communication between Discord server members and the administration team. It allows users to initiate a private support channel within the Discord guild by interacting with a button, ensuring that support requests are organized and restricted to relevant personnel.
Sources: README.md:12, src/interactions/buttonHandlers.js:14-15
System Architecture and Integration
The ticketing system is part of the Discord bot service (bot.js) and is triggered via button interactions handled in the src/interactions module. The flow relies on specific Discord server configurations, such as category naming and role assignments, to function correctly.
Component Interaction
- Interaction Entry: The
bot.jsentry point registers an interaction handler which listens for all button clicks. - Logic Routing: When a button with the
customIdofcreate_ticketis pressed, the request is routed to thehandleTicketCreationfunction. - Discord API: The bot interacts with the Discord API to check for existing channels, create new text channels, and set granular permission overwrites.
Sources: bot.js:25, src/interactions/buttonHandlers.js:13-17, AGENTS.md:27-28
Detailed Flow Logic
The following sequence diagram illustrates the step-by-step process from the moment a user clicks the "Create Ticket" button to the final confirmation.
Validations and Constraints
Before creating a channel, the system performs several checks:
- Category Check: The bot looks for a Guild Category named "ticket" (case-insensitive). If this category is missing, the process fails to ensure tickets are not created in the root of the server.
- Duplicate Prevention: The bot searches the guild's channel cache for an existing channel where the
topicmatchesTicket for [member.id]. This prevents a single user from spamming multiple support channels. - Permissions: The bot requires "Manage Channels" and "Manage Messages" permissions to properly set up the environment.
Sources: src/interactions/buttonHandlers.js:24-46
Channel Configuration and Permissions
When a ticket is successfully created, the bot applies specific configurations to the new channel to maintain privacy.
Channel Attributes
| Property | Value / Format |
|---|---|
| Name | ticket-[username] (Sanitized to alphanumeric and dashes) |
| Type | GuildText |
| Parent | The "ticket" category ID |
| Topic | Ticket for [member.id] |
Sources: src/interactions/buttonHandlers.js:90-95
Permission Overwrites
The bot sets strict permission overwrites to ensure only the user and the staff can see the ticket:
| Entity | Deny Permissions | Allow Permissions |
|---|---|---|
| @everyone | ViewChannel | - |
| User | - | ViewChannel, SendMessages, ReadMessageHistory |
| Bot | - | ViewChannel, SendMessages, ReadMessageHistory, ManageMessages, ManageChannels |
| Discord Admin Role | - | ViewChannel, SendMessages, ReadMessageHistory, ManageMessages, ManageChannels |
Sources: src/interactions/buttonHandlers.js:52-87
Implementation Details
The implementation utilizes discord.js v14 features, including PermissionFlagsBits for access control and MessageFlags.Ephemeral to ensure error or status messages are only visible to the user who triggered the interaction.
// src/interactions/buttonHandlers.js:90-96
const ticketChannel = await guild.channels.create({
name: `ticket-${member.user.username}`.toLowerCase().replace(/[^a-z0-9-]/g, "-"),
type: ChannelType.GuildText,
parent: ticketCategory.id,
topic: `Ticket for ${member.id}`,
permissionOverwrites: overwrites
});
The system also attempts to find a role named "discord admin" to automatically grant staff access to the created channel. If the role is found, it is included in the overwrites array.
Sources: src/interactions/buttonHandlers.js:48-50, src/interactions/buttonHandlers.js:77-87
Conclusion
The Ticket Creation Flow provides a robust, automated method for user support. By validating the server structure (the "ticket" category) and enforcing unique tickets per user via channel topics, the system maintains high organizational standards. The use of ephemeral responses and strict permission overwrites ensures user privacy and a clean user interface within the TarkovTracker community Discord.