yuvrau

andd add that option that bot will send transcript in a perticular channel in whose id I given in .env

--- ๐Ÿ“Ž Attached 1 file(s):

File: pasted-code-1786038401468.txt

txt
create an optimized all in one discord ticket bot 

with embed message and options and staff role and at 1 time people can open only one ticket at once and another can open after last one is closed and all options ticket have there own category and after open the ticket 

the ticket channel should be name {category name } - {ticket Opener name } 

and add some important command by yourself and some I will tell like /ticket close 

/ticket setup and all data and while setupping the ticket opening embed message it will ass for tittle , description , banner and /ticket category by this it will add category and then only /ticket setup command work and also add /removeticket category and ticket embed should be choose at /ticket setup command and which color is choosen that color also make the embed in ticket and the message what user write while opening it and it will ping staff team and ticket opener 

and add /ticket-pin command  by this when ever this command is run in any ticket it will renamed and add the emoji in the starting name and orignal ticket name should be remain and by this command that ticket should be pinned at pinned ticket category 

and add transcript system that ticket bot send transcript in html form for example I am givinmg you like this it look like the image off whole chat and I amd giving you some other images also for example 
3 images attached
Kodari AI
KodariAug 6 at 5:51 pm 2
TicketMasterPro
A comprehensive Discord ticket bot with embed-based ticket creation, category management, and staff role support. Users can open only one ticket at a time, with channels named by category and opener. Includes /ticket setup for configuring title, description, banner, and color; /ticket category management; /ticket close; /ticket-pin to pin tickets with emoji; and automatic HTML transcript delivery to a designated channel specified in .env. All ticket options have dedicated categories, and opening messages ping both staff and the ticket opener.
  1. Create the Discord.js bot foundation, persistence, and environment configuration.

  2. Add ticket setup/category management, modal-based ticket creation, staff permissions, single-open-ticket enforcement, close, and pin behavior.

  3. Add HTML transcript generation and delivery to the TRANSCRIPT_CHANNEL_ID configured in .env.

  1. Created a complete Discord.js ticket bot with persistent JSON storage and .env configuration.

  2. Added ticket categories, setup panel embeds, custom colors, banner images, staff roles, and modal-based ticket opening.

  3. Added one-open-ticket-per-user enforcement, ticket-specific categories, ticket naming, /ticket close, and staff-only /ticket-pin.

  4. Added HTML transcript generation and automatic upload to the channel configured with TRANSCRIPT_CHANNEL_ID.

  5. Added setup documentation and command reference in README.md.

Run:

Shell
npm install
cp .env.example .env
npm start

Set TRANSCRIPT_CHANNEL_ID in .env to the channel where closed-ticket transcripts should be sent.

Kodari can make mistakes. Review important code before using.
Files
.gitignore
index.js
package.json
README.md
Code
4 766
index.js
require('dotenv').config();

const fs = require('node:fs');
const path = require('node:path');
const {
  ActionRowBuilder,
  AttachmentBuilder,
  ButtonBuilder,
  ButtonStyle,
  ChannelType,
  Client,
  EmbedBuilder,
  Events,
  GatewayIntentBits,
  PermissionFlagsBits,
  REST,
  Routes,
  SlashCommandBuilder,
  StringSelectMenuBuilder,
  TextInputBuilder,
  TextInputStyle,
  ModalBuilder,
} = require('discord.js');

const DATA_FILE = path.resolve(process.env.DATA_FILE || './data/tickets.json');
const PANEL_CUSTOM_ID = 'ticket:create';
const CLOSE_BUTTON_CUSTOM_ID = 'ticket:close';
const PIN_BUTTON_CUSTOM_ID = 'ticket:pin';
const DEFAULT_COLOR = 0x5865f2;

const client = new Client({
  intents: [
    GatewayIntentBits.Guilds,
    GatewayIntentBits.GuildMessages,
    GatewayIntentBits.MessageContent,
  ],
});

function loadData() {
  try {
    const parsed = JSON.parse(fs.readFileSync(DATA_FILE, 'utf8'));
    return parsed && parsed.guilds ? parsed : { guilds: {} };
  } catch (error) {
    if (error.code !== 'ENOENT') {
      console.error('Could not read ticket data, starting with an empty store:', error.message);
    }
    return { guilds: {} };
  }
}

const data = loadData();

function saveData() {
  fs.mkdirSync(path.dirname(DATA_FILE), { recursive: true });
  fs.writeFileSync(DATA_FILE, JSON.stringify(data, null, 2));
}

function getGuildConfig(guildId) {
  if (!data.guilds[guildId]) {
    data.guilds[guildId] = {
      staffRoleId: null,
      panelChannelId: null,
      panelMessageId: null,
      title: 'Support Tickets',
      description: 'Select a category below to open a ticket.',
      banner: null,
      color: DEFAULT_COLOR,
      pinnedCategoryId: null,
      categories: {},
      tickets: {},
      activeTickets: {},
    };
  }

  const config = data.guilds[guildId];
  config.categories ||= {};
  config.tickets ||= {};
  config.activeTickets ||= {};
  return config;
}

function slugify(value) {
  const slug = value
    .toLowerCase()
    .replace(/[^a-z0-9]+/g, '-')
    .replace(/^-+|-+$/g, '')
    .slice(0, 45);
  return slug || 'ticket';
}

function parseColor(value) {
  if (!value) return DEFAULT_COLOR;
  const normalized = value.trim().replace(/^#/, '').replace(/^0x/i, '');
  if (!/^[0-9a-f]{6}$/i.test(normalized)) return null;
  return Number.parseInt(normalized, 16);
}

function isHttpUrl(value) {
  if (!value) return true;
  try {
    const url = new URL(value);
    return url.protocol === 'http:' || url.protocol === 'https:';
  } catch {
    return false;
  }
}

function escapeHtml(value) {
  return String(value ?? '')
    .replaceAll('&', '&')
    .replaceAll('<', '&lt;')
    .replaceAll('>', '&gt;')
    .replaceAll('"', '&quot;')
    .replaceAll("'", '&#039;');
}

function safeFilePart(value) {
  return String(value || 'ticket').replace(/[^a-z0-9-_]/gi, '-').slice(0, 50) || 'ticket';
}

function isStaff(member, config) {
  return Boolean(
    member?.roles?.cache?.has(config.staffRoleId) ||
      member?.permissions?.has(PermissionFlagsBits.ManageChannels),
  );
}

function isManager(interaction) {
  return Boolean(
    interaction.memberPermissions?.has(PermissionFlagsBits.ManageGuild) ||
      interaction.memberPermissions?.has(PermissionFlagsBits.Administrator),
  );
}

function ticketPermissionOverwrites(guild, config, userId) {
  const staffPermissions = [
    PermissionFlagsBits.ViewChannel,
    PermissionFlagsBits.SendMessages,
    PermissionFlagsBits.ReadMessageHistory,
    PermissionFlagsBits.AttachFiles,
    PermissionFlagsBits.EmbedLinks,
    PermissionFlagsBits.ManageMessages,
  ];

  const overwrites = [
    {
      id: guild.roles.everyone.id,
      deny: [PermissionFlagsBits.ViewChannel],
    },
    {
      id: userId,
      allow: [
        PermissionFlagsBits.ViewChannel,
        PermissionFlagsBits.SendMessages,
        PermissionFlagsBits.ReadMessageHistory,
        PermissionFlagsBits.AttachFiles,
        PermissionFlagsBits.EmbedLinks,
      ],
    },
  ];

  if (config.staffRoleId && guild.roles.cache.has(config.staffRoleId)) {
    overwrites.push({ id: config.staffRoleId, allow: staffPermissions });
  }
  return overwrites;
}

function buildPanel(config) {
  const embed = new EmbedBuilder()
    .setTitle(config.title)
    .setDescription(config.description)
    .setColor(config.color || DEFAULT_COLOR);

  if (config.banner) embed.setImage(config.banner);

  const options = Object.entries(config.categories).map(([key, category]) => {
    const option = {
      label: category.name.slice(0, 100),
      value: key,
      description: category.description.slice(0, 100),
    };
    if (category.emoji) option.emoji = { name: category.emoji };
    return option;
  });

  const menu = new StringSelectMenuBuilder()
    .setCustomId(PANEL_CUSTOM_ID)
    .setPlaceholder('Select a ticket category')
    .addOptions(options);

  return {
    embeds: [embed],
    components: [new ActionRowBuilder().addComponents(menu)],
  };
}

function buildTicketButtons() {
  return new ActionRowBuilder().addComponents(
    new ButtonBuilder()
      .setCustomId(CLOSE_BUTTON_CUSTOM_ID)