Advertisement
Danulsan

Untitled

Jun 27th, 2023
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.35 KB | None | 0 0
  1. const { Client, GatewayIntentBits, EmbedBuilder, PermissionsBitField, Permissions, MessageManager, Embed, Collection, Events, Partials, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder } = require(`discord.js`);
  2. const fs = require('fs');
  3. const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent, GatewayIntentBits.GuildMessageReactions], partials: [Partials.Message, Partials.Channel, Partials.Reaction] });
  4. const reactions = require('./Schemas.js/reactionjs');
  5. const ticketSchema = require("./Schemas.js/ticketSchema");
  6.  
  7. client.commands = new Collection();
  8.  
  9. require('dotenv').config();
  10.  
  11. const functions = fs.readdirSync("./src/functions").filter(file => file.endsWith(".js"));
  12. const eventFiles = fs.readdirSync("./src/events").filter(file => file.endsWith(".js"));
  13. const commandFolders = fs.readdirSync("./src/commands");
  14.  
  15. (async () => {
  16. for (file of functions) {
  17. require(`./functions/${file}`)(client);
  18. }
  19. client.handleEvents(eventFiles, "./src/events");
  20. client.handleCommands(commandFolders, "./src/commands");
  21. client.login(process.env.token)
  22. })();
  23.  
  24. client.on(Events.MessageReactionAdd, async (reaction, user) => {
  25. let a = 3;
  26. if (!reaction.message.guildId) return;
  27. if (user.bot) return
  28.  
  29. let cID = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
  30. if (!reaction.emoji.id) cID = reaction.emoji.name;
  31.  
  32. const data = await reactions.findOne({ Guild: reaction.message.guildId, Message: reaction.message.id, Emoji: cID });
  33.  
  34. if (!data) return;
  35.  
  36. const guild = await client.guilds.cache.get(reaction.message.guildId);
  37. const member = await guild.members.cache.get(user.id)
  38.  
  39. try {
  40. await member.roles.add(data.Role);
  41. } catch (e) {
  42. return;
  43. }
  44. });
  45.  
  46.  
  47. client.on(Events.MessageReactionRemove, async (reaction, user) => {
  48. if (!reaction.message.guildId) return;
  49. if (user.bot) return
  50.  
  51. let cID = `<:${reaction.emoji.name}:${reaction.emoji.id}>`;
  52. if (!reaction.emoji.id) cID = reaction.emoji.name;
  53.  
  54. const data = await reactions.findOne({ Guild: reaction.message.guildId, Message: reaction.message.id, Emoji: cID });
  55.  
  56. if (!data) return;
  57.  
  58. const guild = await client.guilds.cache.get(reaction.message.guildId);
  59. const member = await guild.members.cache.get(user.id)
  60.  
  61. try {
  62. await member.roles.remove(data.Role);
  63. } catch (e) {
  64. return;
  65. }
  66. });
  67.  
  68.  
  69. //ticket system
  70. client.on(Events.InteractionCreate, async interaction => {
  71.  
  72. if (interaction.isButton()) return;
  73. if (interaction.isChatInputCommand()) return;
  74.  
  75. const modal = new ModalBuilder()
  76. .setTitle("Provide us with more information.")
  77. .setCustomId("modal")
  78.  
  79. const email = new TextInputBuilder()
  80. .setCustomId("email")
  81. .setRequired(true)
  82. .setLabel("Provide us with your email.")
  83. .setPlaceholder("You must enter a valid email")
  84. .setStyle(TextInputStyle.Short)
  85.  
  86. const username = new TextInputBuilder()
  87. .setCustomId("username")
  88. .setRequired(true)
  89. .setLabel("Provide us with your username please.")
  90. .setPlaceholder("Username")
  91. .setStyle(TextInputStyle.Short)
  92.  
  93. const reason = new TextInputBuilder()
  94. .setCustomId("reason")
  95. .setRequired(true)
  96. .setLabel("The reason for this ticket?")
  97. .setPlaceholder("Give us a reason for opening this ticket")
  98. .setStyle(TextInputStyle.Short)
  99.  
  100. const firstActionRow = new ActionRowBuilder().addComponents(email)
  101. const secondActionRow = new ActionRowBuilder().addComponents(username)
  102. const thirdActionRow = new ActionRowBuilder().addComponents(reason)
  103.  
  104. modal.addComponents(firstActionRow, secondActionRow, thirdActionRow);
  105.  
  106. let choices;
  107. if (interaction.isSelectMenu()) {
  108.  
  109. choices = interaction.values;
  110.  
  111. const result = choices.join("");
  112.  
  113. ticketSchema.findOne({ Guild: interaction.guild.id }, async (err, data) => {
  114.  
  115. const filter = { Guild: interaction.guild.id };
  116. const update = { Ticket: result };
  117.  
  118. ticketSchema.updateOne(filter, update, {
  119. new: true
  120. }).then(value => {
  121. console.log(value)
  122. })
  123. })
  124. }
  125.  
  126. if (!interaction.isModalSubmit()) {
  127. interaction.showModal(modal)
  128. }
  129. })
  130.  
  131. client.on(Events.InteractionCreate, async interaction => {
  132.  
  133. if (interaction.isModalSubmit()) {
  134.  
  135. if (interaction.customId == "modal") {
  136.  
  137. ticketSchema.findOne({ Guild: interaction.guild.id }, async (err, data) => {
  138.  
  139. const emailInput = interaction.fields.getTextInputValue("email")
  140. const usernameInput = interaction.fields.getTextInputValue("username")
  141. const reasonInput = interaction.fields.getTextInputValue("reason")
  142.  
  143. const posChannel = await interaction.guild.channels.cache.find(c => c.name === `ticket-${interaction.user.id}`);
  144. if (posChannel) return await interaction.reply({ content: `You already have a ticket open - ${posChannel}`, ephemeral: true });
  145.  
  146. const category = data.Channel;
  147.  
  148. const embed = new EmbedBuilder()
  149. .setColor("Blue")
  150. .setTitle(`${interaction.user.id}'s Ticket`)
  151. .setDescription("Welcome to your ticket! Please wait while the staff team review the details.")
  152. .addFields({ name: `Email`, value: `${emailInput}` })
  153. .addFields({ name: `Username`, value: `${usernameInput}` })
  154. .addFields({ name: `Reason`, value: `${reasonInput}` })
  155. .addFields({ name: `Type`, value: `${data.Ticket}` })
  156. .setFooter({ text: `${interaction.guild.name}'s tickets.` })
  157.  
  158. const button = new ActionRowBuilder()
  159. .addComponents(
  160. new ButtonBuilder()
  161. .setCustomId("ticket")
  162. .setLabel("🗑️ Close Ticket")
  163. .setStyle(ButtonStyle.Danger)
  164. )
  165.  
  166. let channel = await interaction.guild.channels.create({
  167. name: `ticket-${interaction.user.id}`,
  168. type: ChannelType.GuildText,
  169. parent: `${category}`
  170. })
  171.  
  172. let msg = await channel.send({ embeds: [embed], components: [button] });
  173. await interaction.reply({ content: `Your ticket is now open inside of ${channel}.`, ephemeral: true });
  174.  
  175. const collector = msg.createMessageComponentCollector()
  176.  
  177. collector.on("collect", async i => {
  178. await channel.delete();
  179.  
  180. const dmEmbed = new EmbedBuilder()
  181. .setColor("Blue")
  182. .setTitle("Your ticket has been closed")
  183. .setDescription("Thanks for contacting us! If you need anything else just feel free to open up another ticket!")
  184. .setTimestamp()
  185.  
  186. await interaction.member.send({ embeds: [dmEmbed] }).catch(err => {
  187. return;
  188. })
  189. })
  190. })
  191. }
  192. }
  193. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement