Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import fs from 'fs';
- import Discord from 'discord.js';
- import config from './config.mjs';
- import { REST } from '@discordjs/rest';
- import { Routes } from 'discord-api-types/v9';
- const { token, prefix, embedColor } = config;
- const intents = new Discord.Intents([Discord.Intents.FLAGS.GUILDS, Discord.Intents.FLAGS.GUILD_MESSAGES]);
- const clientId = '1089335827261296711';
- const client = new Discord.Client({ intents });
- const guildId = '1010973375755190422';
- client.on('ready', () => {
- console.log(`Logged in as ${client.user.tag}!`);
- const rest = new REST({ version: '9' }).setToken(token);
- rest.put(Routes.applicationCommands(clientId), {
- body: [
- {
- name: 'ping',
- description: 'Ping pong command',
- },
- ],
- })
- .then(() => console.log('Successfully registered application commands.'))
- .catch(console.error);
- });
- client.login(token);
- client.on('ready', async () => {
- console.log(`Logged in as ${client.user.tag}!`);
- // Register slash commands
- try {
- const commands = [
- {
- name: 'newticket',
- description: 'Creates a new support ticket.'
- },
- {
- name: 'closeticket',
- description: 'Closes an existing support ticket.'
- },
- {
- name: 'addstaff',
- description: 'Adds a user as staff to the bot.'
- },
- {
- name: 'removestaff',
- description: 'Removes a user from the bot\'s staff.'
- },
- {
- name: 'liststaff',
- description: 'Lists all current staff members.'
- },
- {
- name: 'setprefix',
- description: 'Changes the command prefix for the bot.'
- },
- {
- name: 'setcolor',
- description: 'Changes the default color for embed messages.'
- },
- {
- name: 'setcategory',
- description: 'Sets the category where new tickets will be created.'
- },
- {
- name: 'setlogs',
- description: 'Sets the channel where logs for the bot will be sent.'
- },
- {
- name: 'help',
- description: 'Displays a list of available commands and their descriptions.'
- }
- ];
- const rest = new REST({ version: '9' }).setToken(token);
- await rest.put(
- Routes.applicationGuildCommands(clientId, guildId),
- { body: commands },
- );
- console.log('Slash commands registered!');
- } catch (error) {
- console.error(error);
- }
- });
- client.on('interactionCreate', async interaction => {
- if (!interaction.isCommand()) return;
- const { commandName } = interaction;
- client.on('interactionCreate', async interaction => {
- if (!interaction.isCommand()) return;
- const { commandName } = interaction;
- const botOwnerId = '126078745240010755'
- if (commandName === 'shutdown') {
- // Only allow the bot owner to shutdown the bot
- if (interaction.user.id !== process.env.botOwnerId) {
- return interaction.reply('You do not have permission to use this command.');
- }
- // Shutdown the bot
- await interaction.reply('Shutting down...');
- await client.destroy();
- process.exit();
- }
- });
- if (commandName === 'ticket') {
- const user = interaction.user;
- const name = interaction.options.getString('name');
- await interaction.deferReply({ ephemeral: true });
- const channel = await interaction.guild.channels.create(`${user.username}-${name}`, {
- type: 'text',
- topic: `Ticket created by ${user.tag}`,
- parent: '1037524404776742962'
- });
- const embed = new MessageEmbed()
- .setTitle(`Welcome to your ticket, ${user.username}!`)
- .setDescription(`Please provide us with the necessary information below so we can assist you better.`)
- .setColor(config.embedColor);
- const menu = new MessageActionRow()
- .addComponents(
- new MessageSelectMenu()
- .setCustomId('category_select')
- .setPlaceholder('Please select a category')
- .addOptions([
- {
- label: 'Technical Support',
- description: 'Get help with technical issues',
- value: 'tech_support'
- },
- {
- label: 'General Inquiry',
- description: 'Ask a general question',
- value: 'general_inquiry'
- },
- {
- label: 'Billing',
- description: 'Get help with billing or payments',
- value: 'billing'
- },
- ]),
- );
- const form = new MessageActionRow()
- .addComponents(
- new MessageButton()
- .setCustomId('add_question')
- .setLabel('Add Question')
- .setStyle('PRIMARY')
- .setEmoji('➕'),
- new MessageButton()
- .setCustomId('remove_question')
- .setLabel('Remove Question')
- .setStyle('DANGER')
- .setEmoji('➖'),
- );
- await channel.send({ embeds: [embed], components: [menu, form] });
- const ticketData = {
- id: channel.id,
- creatorId: user.id,
- questions: []
- };
- const tickets = JSON.parse(fs.readFileSync('./tickets.json', 'utf8'));
- tickets.push(ticketData);
- fs.writeFileSync('./tickets.json', JSON.stringify(tickets));
- await interaction.editReply('Your ticket has been created!');
- }
- });
- client.on('interactionCreate', async interaction => {
- if (!interaction.isSelectMenu()) return;
- const { customId, values } = interaction;
- if (customId === 'category_select') {
- const category = values[0];
- const categoryId = 'insert your category id here';
- const questions = [];
- switch (category) {
- case 'tech_support':
- questions.push({
- title: 'What is the issue you are experiencing?',
- placeholder: 'Please describe the issue in as much detail as possible.',
- type: 'multi-line',
- minLength: 10,
- maxLength: 2000
- });
- questions.push({
- title: 'What steps have you taken to try and resolve the issue?',
- placeholder: 'Please describe any steps you have taken in as much detail as possible.',
- type: 'multi-line',
- minLength: 10,
- maxLength: 2000
- });
- createTicketChannel(interaction, 'Tech Support', 'tech_support', questions);
- break;
- case 'billing':
- questions.push({
- title: 'What is your billing question?',
- placeholder: 'Please describe your billing question in as much detail as possible.',
- type: 'multi-line',
- minLength: 10,
- maxLength: 2000
- });
- createTicketChannel(interaction, 'Billing', 'billing', questions);
- break;
- case 'other':
- questions.push({
- title: 'What is the reason for your ticket?',
- placeholder: 'Please describe your reason in as much detail as possible.',
- type: 'multi-line',
- minLength: 10,
- maxLength: 2000
- });
- createTicketChannel(interaction, 'Other', 'other', questions);
- break;
- default:
- break;
- }
- }
- });
- client.login(token);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement