Untitled
unknown
plain_text
2 years ago
4.8 kB
14
Indexable
const { Client, GatewayIntentBits, EmbedBuilder, ActionRowBuilder, ButtonBuilder, ButtonStyle,ChannelType, PermissionsBitField } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMembers] });
const discordTranscripts = require('discord-html-transcripts');
const ticketPanelChannelId = '1225124137215852634';
const supportRoleId = '1208305738737262602'; // Replace with actual ID
const transcriptChannelId = '1225145709435687015'; // Replace with actual ID
const closeTicketTimeout = 10;
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
client.user.setStatus('dnd');
sendTicketPanel();
});
client.on('interactionCreate', async interaction => {
if (!interaction.isButton()) return;
if (interaction.customId === 'createTicket') {
const guild = interaction.guild;
const ticketCreator = interaction.user;
// Generate a channel name (customize as needed)
const ticketName = `ticket-${ticketCreator.id}`;
try {
console.log('ticketName:', ticketName);
const channel = await guild.channels.create({
name: ticketName,
type: ChannelType.GuildText,
permissionOverwrites: [
{
id: ticketCreator.id,
allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory]
},
{
id: guild.id,
deny: [PermissionsBitField.Flags.ViewChannel]
},
]
});
// Welcome embed
const embed = new EmbedBuilder()
.setTitle(`Welcome to your Ticket, ${ticketCreator.username}!`)
.setDescription('A support member will be with you shortly.')
.setColor(0x00ffff) // Light blue color
.setFooter({
text: 'Please describe your issue in detail.',
});
const button = new ActionRowBuilder().addComponents(
new ButtonBuilder()
.setCustomId('closeTicket')
.setLabel('Close Ticket')
.setStyle(ButtonStyle.Danger) // Red colored button
);
await channel.send({ embeds: [embed], components: [button] });
// Send DM to ticket opener
await ticketCreator.send({
content: `Your ticket has been created: ${channel}`,
});
} catch (error) {
console.error('Error creating ticket channel:', error);
interaction.reply({
content: 'There was an error creating your ticket. Please try again, or contact a staff member.',
ephemeral: true,
});
}
}else if (interaction.customId === 'closeTicket') {
const channel = interaction.channel;
if (channel.type !== ChannelType.GuildText) return;
// Generate Transcript
const messages = await channel.messages.fetch({ limit: 100 });
const attachment = await discordTranscripts.createTranscript(messages);
// Send Transcript
const transcriptChannel = client.channels.cache.get(transcriptChannelId);
await transcriptChannel.send({
content: `**Ticket Transcript for #${channel.name}**`,
files: [attachment],
});
// Close Channel
await channel.send({ content: 'This ticket will close in 5 seconds.' });
setTimeout(async () => {
await channel.delete();
// Notify Ticket Opener
const ticketCreator = await client.users.fetch(channel.name.split('-')[1]);
await ticketCreator.send({
content: `Your ticket (#${channel.name}) has been closed. A transcript has been sent to the transcript channel.`,
});
}, closeTicketTimeout * 1000);
}
});
function sendTicketPanel() {
const ticketChannel = client.channels.cache.get(ticketPanelChannelId);
const embed = new EmbedBuilder()
.setTitle('Create a Ticket')
.setDescription('Need help? Click the button below to open a new support ticket!');
const button = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId('createTicket')
.setLabel('Create Ticket')
.setStyle(ButtonStyle.Primary)
);
ticketChannel.send({ embeds: [embed], components: [button] });
}
client.login('Hiideno');Editor is loading...
Leave a Comment