discord-ticket-easy
Version:
- A module allowing the simple creation of a discord ticket with your client supported by Discord.js^14.0.0 - The easiest to use ticket module.
136 lines (110 loc) • 6.22 kB
JavaScript
const Discord = require("discord.js");
const Client = require("./Client");
module.exports = class Interaction {
/**
*
* @param {Discord.Client} client
* @param {Discord.this.interaction} interaction
*/
constructor(client, interaction) {
this.client = client
this.localClient = Client
this.rolesID = Client.data.moduleData.roleId
this.channelID = Client.data.moduleData.channelMessageID
this.categorieID = Client.data.moduleData.categorieID
this.categorieArchiveID = Client.data.moduleData.categorieArchiveID
this.guildID = Client.data.moduleData.guildID
this.interaction = interaction
}
async start() {
if (await this.localClient.isValidApiKey() === false) {
throw new Error("Your api key is not valid! Check your vogzcorp profile.")
}
if (this.interaction.type == Discord.InteractionType.MessageComponent) {
if (this.interaction.customId == "newTicket") {
if (this.guildID == null || this.guildID == undefined) return this.interaction.reply({content: "Please configure the module before using it", ephemeral: true}).catch(err => console.log(err))
let guild = this.client.guilds.fetch(this.guildID)
let channelFetch = (await guild).channels.cache.find(c => c.topic == this.interaction.user.id);
let channelArchive = (await guild).channels.cache.find(c => c.topic === `${this.interaction.user.id} | archivé`)
if (channelFetch || channelArchive) return this.interaction.reply({content: `You already have an open ticket! (${channelFetch === undefined ? channelArchive : channelFetch})`, ephemeral: true}).catch(err => console.log(err))
let channel = await (await guild).channels.create({
name: `ticket-${this.interaction.user.username}`,
type: Discord.ChannelType.GuildText,
permissionOverwrites: [
{
id: this.interaction.user.id,
allow: [Discord.PermissionFlagsBits.ViewChannel]
},
{
id: (await guild).roles.everyone.id,
deny: [Discord.PermissionFlagsBits.ViewChannel]
},
{
id: this.rolesID[0],
allow: [Discord.PermissionFlagsBits.ViewChannel]
}
],
topic: `${this.interaction.user.id}`,
parent: (await guild).channels.cache.get(this.categorieID)
})
let Embed = new Discord.EmbedBuilder()
.setTitle(`Ticket - ${this.interaction.user.username}`)
.setDescription("To or archive this ticket, you can click on the button of your choice below")
.setFooter({text: "EmbedTicket - discord-ticket-easy"})
let button = new Discord.ActionRowBuilder()
.addComponents(
new Discord.ButtonBuilder()
.setCustomId("archive")
.setLabel('archive')
.setEmoji("🔒")
.setStyle(Discord.ButtonStyle.Secondary)
)
.addComponents(
new Discord.ButtonBuilder()
.setCustomId("delete")
.setLabel('delete')
.setEmoji("⛔")
.setStyle(Discord.ButtonStyle.Danger)
)
channel.send({embeds: [Embed], components: [button]});
return await this.interaction.reply({content: "Your ticket has been successfully created", ephemeral: true}).catch(err => console.log(err))
}
}
if (this.interaction.type == Discord.InteractionType.MessageComponent) {
let guild = this.client.guilds.fetch(this.guildID)
let channel = (await guild).channels.cache.find(c => c.topic === this.interaction.user.id)
if (this.interaction.customId == "archive") {
let channelArchive = (await guild).channels.cache.find(c => c.topic === `${this.interaction.user.id} | archivé`)
if (channelArchive?.parentId === this.categorieArchiveID) return this.interaction.reply({content: "You cannot archive a ticket that has already been archived!", ephemeral: true}).catch(err => console.log(err))
await channel.setParent(this.categorieArchiveID)
await channel.setName(`${this.interaction.user.username}-archive`)
await channel.setTopic(`${channel.topic} | archivé`)
await channel.permissionOverwrites.set([
{
id: this.interaction.user.id,
deny: [Discord.PermissionFlagsBits.ViewChannel],
},
{
id: (await guild).roles.everyone.id,
deny: [Discord.PermissionFlagsBits.ViewChannel]
}
])
return this.interaction.reply({content: "You have successfully archived this ticket!", ephemeral: true}).catch(err => console.log(err))
}
if (this.interaction.customId == "delete") {
let channelArchive = (await guild).channels.cache.find(c => c.topic === `${this.interaction.user.id} | archivé`)
if (!channelArchive || channelArchive == null) {
channel.delete().catch(err => console.log(err));
return this.interaction.user.send({content: "You have successfully deleted your ticket!"})
}
channelArchive.delete().catch(err => console.log(err));
return this.interaction.user.send({content: "You have successfully deleted your ticket!"})
}
}
if (this.interaction.type == Discord.InteractionType.MessageComponent) {
if (this.interaction.customId == "aboutPremium") {
return this.interaction.reply({content: `Premium not yet available. (Be there soon)`, ephemeral: true})
}
}
}
}