LakeBigHead

Untitled

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