Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import {
- GuildChannel,
- Message,
- MessageEmbed,
- TextChannel,
- MessageActionRow,
- MessageButton,
- } from "discord.js";
- import { TicketPanel } from "../entity/Panel";
- import { Tickets } from "../entity/Tickets";
- import { BotClient } from "../interfaces/BotClient";
- // setup basic command module
- module.exports = {
- name: "accept",
- description: "Accept a ticket",
- usage: "accept [@roles]",
- aliases: ["ticketaccept"],
- async execute(
- message: Message,
- client: BotClient,
- args: string[]
- ): Promise<void> {
- // check if the ticket is a valid application or ban appeal
- if (
- !(
- (message.channel as TextChannel).name.startsWith("application") ||
- (message.channel as TextChannel).name.startsWith("ban")
- )
- ) {
- // sends a embed with description "This is not a valid ticket channel" in red color embed
- let embed = new MessageEmbed()
- .setColor("#ff0000")
- .setDescription("This is not a valid ticket channel");
- message.channel.send({ embeds: [embed] });
- return;
- }
- // get the ticket through typeorm repoistory to make sure it exists
- const ticket = await client.orm.getRepository(Tickets).findOne({
- where: {
- ticketChannelId: message.channel.id,
- },
- });
- // if the ticket is not found, send a embed with description "This is not a ticket channel" in red color embed
- if (!ticket) {
- let embed = new MessageEmbed()
- .setColor("#ff0000")
- .setDescription("This is not a ticket channel");
- message.channel.send({ embeds: [embed] });
- return;
- }
- // get the type of ticket
- const ticketType = ticket.ticketType;
- let ticketHandler = null;
- // check if the ticketType is application, if it is set ticketHandler to applicationReviewerRoles from config else set it to banAppealRoles
- if (ticketType === "application") {
- ticketHandler = client.config.applicationReviewerRoles;
- } else {
- ticketHandler = client.config.banAppealRoles;
- }
- // check if the author has any of the role from array ticketHandler
- if (!ticketHandler.some((role) => message.member.roles.cache.has(role))) {
- // sends a embed with description "You don't have permission to run this command" in red color embed
- let embed = new MessageEmbed()
- .setColor("#ff0000")
- .setDescription("You don't have permission to run this command");
- message.channel.send({ embeds: [embed] });
- return;
- }
- // get the Panel through orm using guild id
- const panel = await client.orm.getRepository(TicketPanel).findOne({
- guild: message.guild.id,
- });
- if (!panel) {
- // send a embed with description "Unable to locate panel for this guild" in red color embed
- let embed = new MessageEmbed()
- .setColor("#ff0000")
- .setDescription("Unable to locate panel for this guild");
- message.channel.send({ embeds: [embed] });
- return;
- }
- let acceptedCategory = panel.approvedCategory;
- // move the ticket to the denied category
- (message.channel as GuildChannel).setParent(acceptedCategory);
- // remove the permission to send message from the owner
- (message.channel as TextChannel).permissionOverwrites.edit(ticket.userId, {
- SEND_MESSAGES: false,
- ADD_REACTIONS: false,
- CREATE_PUBLIC_THREADS: false,
- });
- (message.channel as TextChannel).permissionOverwrites.edit(
- message.guild.id,
- {
- SEND_MESSAGES: false,
- VIEW_CHANNEL: false,
- ADD_REACTIONS: false,
- CREATE_PUBLIC_THREADS: false,
- }
- );
- // Create a message with title "Ticket denied", in description "Your ticket has been denied by ${staffMember} on ${Date} for reason ${reason}\n\nYour Ticket UUID is ${TicketUUID}\nPlease react to the following button to close the ticket" and in embed color red
- let deniedEmbed = new MessageEmbed()
- .setColor("#00ff55")
- .setTitle("Ticket accepted")
- .setDescription(`Your ticket has been accepted by our staff team.`)
- .addFields(
- {
- name: "Staff Member",
- value: message.author.username,
- },
- {
- name: "Date",
- value: new Date().toLocaleString(),
- },
- {
- name: "Ticket UUID",
- value: ticket.id,
- }
- );
- if (message.mentions.roles.size > 0)
- deniedEmbed.addField(
- "Roles",
- message.mentions.roles.map((role) => role.toString()).join(", ")
- );
- // Create a button row
- let deniedButtonRow = new MessageActionRow();
- // Create a button to close, with emoji and name "Close Ticket" in Danger style
- let deniedCloseButton = new MessageButton()
- .setCustomId("close")
- .setEmoji("❌")
- .setLabel("Close Ticket")
- .setStyle("DANGER");
- // Add the button to the row
- deniedButtonRow.addComponents(deniedCloseButton);
- // send the row and embed to the channel
- (message.channel as TextChannel).send({
- content: `<@!${ticket.userId}>`,
- embeds: [deniedEmbed],
- components: [deniedButtonRow],
- });
- // find the member ticket.userId
- let member = message.guild.members.cache.get(ticket.userId);
- if (!member) return;
- // loop through all the roles that is mentioned in the command and add it to the ticket owner
- message.mentions.roles.forEach((role) => {
- // add the role to member
- member.roles.add(role);
- });
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement