Advertisement
LakeBigHead

Untitled

Mar 26th, 2023
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.08 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. client.on('interactionCreate', async interaction => {
  102. if (!interaction.isCommand()) return;
  103.  
  104. const { commandName } = interaction;
  105.  
  106. const botOwnerId = '126078745240010755'
  107.  
  108. if (commandName === 'shutdown') {
  109. // Only allow the bot owner to shutdown the bot
  110. if (interaction.user.id !== process.env.botOwnerId) {
  111. return interaction.reply('You do not have permission to use this command.');
  112. }
  113.  
  114. // Shutdown the bot
  115. await interaction.reply('Shutting down...');
  116. await client.destroy();
  117. process.exit();
  118. }
  119. });
  120.  
  121. if (commandName === 'ticket') {
  122. const user = interaction.user;
  123. const name = interaction.options.getString('name');
  124.  
  125. await interaction.deferReply({ ephemeral: true });
  126.  
  127. const channel = await interaction.guild.channels.create(`${user.username}-${name}`, {
  128. type: 'text',
  129. topic: `Ticket created by ${user.tag}`,
  130. parent: '1037524404776742962'
  131. });
  132.  
  133. const embed = new MessageEmbed()
  134. .setTitle(`Welcome to your ticket, ${user.username}!`)
  135. .setDescription(`Please provide us with the necessary information below so we can assist you better.`)
  136. .setColor(config.embedColor);
  137.  
  138. const menu = new MessageActionRow()
  139. .addComponents(
  140. new MessageSelectMenu()
  141. .setCustomId('category_select')
  142. .setPlaceholder('Please select a category')
  143. .addOptions([
  144. {
  145. label: 'Technical Support',
  146. description: 'Get help with technical issues',
  147. value: 'tech_support'
  148. },
  149. {
  150. label: 'General Inquiry',
  151. description: 'Ask a general question',
  152. value: 'general_inquiry'
  153. },
  154. {
  155. label: 'Billing',
  156. description: 'Get help with billing or payments',
  157. value: 'billing'
  158. },
  159. ]),
  160. );
  161.  
  162. const form = new MessageActionRow()
  163. .addComponents(
  164. new MessageButton()
  165. .setCustomId('add_question')
  166. .setLabel('Add Question')
  167. .setStyle('PRIMARY')
  168. .setEmoji('➕'),
  169. new MessageButton()
  170. .setCustomId('remove_question')
  171. .setLabel('Remove Question')
  172. .setStyle('DANGER')
  173. .setEmoji('➖'),
  174. );
  175.  
  176. await channel.send({ embeds: [embed], components: [menu, form] });
  177.  
  178. const ticketData = {
  179. id: channel.id,
  180. creatorId: user.id,
  181. questions: []
  182. };
  183.  
  184. const tickets = JSON.parse(fs.readFileSync('./tickets.json', 'utf8'));
  185.  
  186. tickets.push(ticketData);
  187.  
  188. fs.writeFileSync('./tickets.json', JSON.stringify(tickets));
  189.  
  190. await interaction.editReply('Your ticket has been created!');
  191. }
  192. });
  193.  
  194. client.on('interactionCreate', async interaction => {
  195. if (!interaction.isSelectMenu()) return;
  196.  
  197. const { customId, values } = interaction;
  198.  
  199. if (customId === 'category_select') {
  200. const category = values[0];
  201. const categoryId = 'insert your category id here';
  202.  
  203. const questions = [];
  204.  
  205. switch (category) {
  206. case 'tech_support':
  207. questions.push({
  208. title: 'What is the issue you are experiencing?',
  209. placeholder: 'Please describe the issue in as much detail as possible.',
  210. type: 'multi-line',
  211. minLength: 10,
  212. maxLength: 2000
  213. });
  214. questions.push({
  215. title: 'What steps have you taken to try and resolve the issue?',
  216. placeholder: 'Please describe any steps you have taken in as much detail as possible.',
  217. type: 'multi-line',
  218. minLength: 10,
  219. maxLength: 2000
  220. });
  221. createTicketChannel(interaction, 'Tech Support', 'tech_support', questions);
  222. break;
  223. case 'billing':
  224. questions.push({
  225. title: 'What is your billing question?',
  226. placeholder: 'Please describe your billing question in as much detail as possible.',
  227. type: 'multi-line',
  228. minLength: 10,
  229. maxLength: 2000
  230. });
  231. createTicketChannel(interaction, 'Billing', 'billing', questions);
  232. break;
  233. case 'other':
  234. questions.push({
  235. title: 'What is the reason for your ticket?',
  236. placeholder: 'Please describe your reason in as much detail as possible.',
  237. type: 'multi-line',
  238. minLength: 10,
  239. maxLength: 2000
  240. });
  241. createTicketChannel(interaction, 'Other', 'other', questions);
  242. break;
  243. default:
  244. break;
  245. }
  246. }
  247. });
  248.  
  249. client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement