MCPcopy Create free account
hub / github.com/Sayrix/Ticket-Bot / execute

Method execute

src/events/interactionCreate.ts:22–248  ·  view source on GitHub ↗
(interaction: Interaction)

Source from the content-addressed store, hash-verified

20 }
21
22 public async execute(interaction: Interaction): Promise<void> {
23 if (interaction.isChatInputCommand()) {
24 const command = this.client.commands.get(interaction.commandName);
25 if (!command) return;
26
27 try {
28 await command.execute(interaction);
29 } catch (error) {
30 console.error(error);
31 await interaction.reply({
32 content: "There was an error while executing this command!",
33 ephemeral: true
34 });
35 }
36 }
37
38 if (interaction.isButton()) {
39 if (interaction.customId === "openTicket") {
40 await interaction.deferReply({ ephemeral: true }).catch((e) => console.log(e));
41
42 const tCount = this.client.config.ticketTypes.length;
43 if(tCount === 0 || tCount > 25) {
44 await interaction.followUp({content: this.client.locales.getValue("invalidConfig"), ephemeral: true});
45 throw new Error("ticketTypes either has nothing or exceeded 25 entries. Please check the config and restart the bot");
46 }
47
48 for (const role of this.client.config.rolesWhoCanNotCreateTickets) {
49 if (role && (interaction.member as GuildMember | null)?.roles.cache.has(role)) {
50 interaction
51 .editReply({
52 content: "You can't create a ticket because you are blacklisted"
53 })
54 .catch((e) => console.log(e));
55 return;
56 }
57 }
58
59 // Max Ticket
60 if (this.client.config.maxTicketOpened > 0) {
61 const ticketsOpened = (await this.client.prisma.$queryRaw<[{count: bigint}]>
62 `SELECT COUNT(*) as count FROM tickets WHERE closedby IS NULL AND creator = ${interaction.user.id}`)[0].count;
63
64 // If maxTicketOpened is 0, it means that there is no limit
65 if (ticketsOpened >= this.client.config.maxTicketOpened) {
66 interaction
67 .editReply({
68 content: this.client.locales.getValue("ticketLimitReached").replace("TICKETLIMIT", this.client.config.maxTicketOpened.toString())
69 })
70 .catch((e) => console.log(e));
71 return;
72 }
73 }
74
75 // Make a select menus of all tickets types
76 let options: SelectMenuComponentOptionData[] = [];
77
78 for (const x of this.client.config.ticketTypes) {
79 // x.cantAccess is an array of roles id

Callers

nothing calls this directly

Calls 8

claimFunction · 0.90
closeFunction · 0.90
closeAskReasonFunction · 0.90
deleteTicketFunction · 0.90
createTicketFunction · 0.90
logFunction · 0.90
getValueMethod · 0.80
getSubValueMethod · 0.80

Tested by

no test coverage detected