LakeBigHead

Untitled

Mar 26th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.49 KB | None | 0 0
  1. import fs from 'fs';
  2. import Discord from 'discord.js';
  3. import config from './config.mjs';
  4. import { REST } from '@discordjs/rest';
  5. import { Routes } from 'discord-api-types/v9';
  6.  
  7. const { token, prefix, embedColor } = config;
  8. const intents = new Discord.Intents([Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES]);
  9.  
  10. const clientId = '1089335827261296711';
  11. const client = new Discord.Client({ intents });
  12.  
  13. const guildId = '1010973375755190422';
  14.  
  15. client.on('ready', () => {
  16. console.log(`Logged in as ${client.user.tag}!`);
  17.  
  18. const rest = new REST({ version: '9' }).setToken(token);
  19.  
  20. rest.put(Routes.applicationCommands(clientId), {
  21. body: [
  22. {
  23. name: 'ping',
  24. description: 'Ping pong command',
  25. },
  26. ],
  27. })
  28. .then(() => console.log('Successfully registered application commands.'))
  29. .catch(console.error);
  30. });
  31.  
  32. client.login(token);
  33.  
  34. client.on('ready', async () => {
  35. console.log(`Logged in as ${client.user.tag}!`);
  36.  
  37. // Register slash commands
  38. try {
  39. const commands = [
  40. {
  41. name: 'newticket',
  42. description: 'Creates a new support ticket.'
  43. },
  44. {
  45. name: 'closeticket',
  46. description: 'Closes an existing support ticket.'
  47. },
  48. {
  49. name: 'addstaff',
  50. description: 'Adds a user as staff to the bot.'
  51. },
  52. {
  53. name: 'removestaff',
  54. description: 'Removes a user from the bot\'s staff.'
  55. },
  56. {
  57. name: 'liststaff',
  58. description: 'Lists all current staff members.'
  59. },
  60. {
  61. name: 'setprefix',
  62. description: 'Changes the command prefix for the bot.'
  63. },
  64. {
  65. name: 'setcolor',
  66. description: 'Changes the default color for embed messages.'
  67. },
  68. {
  69. name: 'setcategory',
  70. description: 'Sets the category where new tickets will be created.'
  71. },
  72. {
  73. name: 'setlogs',
  74. description: 'Sets the channel where logs for the bot will be sent.'
  75. },
  76. {
  77. name: 'help',
  78. description: 'Displays a list of available commands and their descriptions.'
  79. }
  80. ];
  81.  
  82. const rest = new REST({ version: '9' }).setToken(token);
  83.  
  84. await rest.put(
  85. Routes.applicationGuildCommands(clientId, guildId),
  86. { body: commands },
  87. );
  88.  
  89. console.log('Slash commands registered!');
  90. } catch (error) {
  91. console.error(error);
  92. }
  93. });
  94.  
  95.  
  96. client.on('interactionCreate', async interaction => {
  97. if (!interaction.isCommand()) return;
  98.  
  99. const { commandName } = interaction;
  100.  
  101. if (commandName === 'ticket') {
  102. const user = interaction.user;
  103. const name = interaction.options.getString('name');
  104.  
  105. await interaction.deferReply({ ephemeral: true });
  106.  
  107. const channel = await interaction.guild.channels.create(`${user.username}-${name}`, {
  108. type: 'text',
  109. topic: `Ticket created by ${user.tag}`,
  110. parent: '1037524404776742962'
  111. });
  112.  
  113. const embed = new MessageEmbed()
  114. .setTitle(`Welcome to your ticket, ${user.username}!`)
  115. .setDescription(`Please provide us with the necessary information below so we can assist you better.`)
  116. .setColor(config.embedColor);
  117.  
  118. const menu = new MessageActionRow()
  119. .addComponents(
  120. new MessageSelectMenu()
  121. .setCustomId('category_select')
  122. .setPlaceholder('Please select a category')
  123. .addOptions([
  124. {
  125. label: 'Technical Support',
  126. description: 'Get help with technical issues',
  127. value: 'tech_support'
  128. },
  129. {
  130. label: 'General Inquiry',
  131. description: 'Ask a general question',
  132. value: 'general_inquiry'
  133. },
  134. {
  135. label: 'Billing',
  136. description: 'Get help with billing or payments',
  137. value: 'billing'
  138. },
  139. ]),
  140. );
  141.  
  142. const form = new MessageActionRow()
  143. .addComponents(
  144. new MessageButton()
  145. .setCustomId('add_question')
  146. .setLabel('Add Question')
  147. .setStyle('PRIMARY')
  148. .setEmoji('➕'),
  149. new MessageButton()
  150. .setCustomId('remove_question')
  151. .setLabel('Remove Question')
  152. .setStyle('DANGER')
  153. .setEmoji('➖'),
  154. );
  155.  
  156. await channel.send({ embeds: [embed], components: [menu, form] });
  157.  
  158. const ticketData = {
  159. id: channel.id,
  160. creatorId: user.id,
  161. questions: []
  162. };
  163.  
  164. const tickets = JSON.parse(fs.readFileSync('./tickets.json', 'utf8'));
  165.  
  166. tickets.push(ticketData);
  167.  
  168. fs.writeFileSync('./tickets.json', JSON.stringify(tickets));
  169.  
  170. await interaction.editReply('Your ticket has been created!');
  171. }
  172. });
  173.  
  174. client.on('interactionCreate', async interaction => {
  175. if (!interaction.isSelectMenu()) return;
  176.  
  177. const { customId, values } = interaction;
  178.  
  179. if (customId === 'category_select') {
  180. const category = values[0];
  181. const categoryId = 'insert your category id here';
  182.  
  183. const questions = [];
  184.  
  185. switch (category) {
  186. case 'tech_support':
  187. questions.push({
  188. title: 'What is the issue you are experiencing?',
  189. placeholder: 'Please describe the issue in as much detail as possible.',
  190. type: 'multi-line',
  191. minLength: 10,
  192. maxLength: 2000
  193. });
  194. questions.push({
  195. title: 'What steps have you taken to try and resolve the issue?',
  196. placeholder: 'Please describe any steps you have taken in as much detail as possible.',
  197. type: 'multi-line',
  198. minLength: 10,
  199. maxLength: 2000
  200. });
  201. createTicketChannel(interaction, 'Tech Support', 'tech_support', questions);
  202. break;
  203. case 'billing':
  204. questions.push({
  205. title: 'What is your billing question?',
  206. placeholder: 'Please describe your billing question in as much detail as possible.',
  207. type: 'multi-line',
  208. minLength: 10,
  209. maxLength: 2000
  210. });
  211. createTicketChannel(interaction, 'Billing', 'billing', questions);
  212. break;
  213. case 'other':
  214. questions.push({
  215. title: 'What is the reason for your ticket?',
  216. placeholder: 'Please describe your reason in as much detail as possible.',
  217. type: 'multi-line',
  218. minLength: 10,
  219. maxLength: 2000
  220. });
  221. createTicketChannel(interaction, 'Other', 'other', questions);
  222. break;
  223. default:
  224. break;
  225. }
  226. }
  227. });
  228.  
  229. client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment