Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {
- Client,
- ChatInputCommandInteraction,
- SlashCommandBuilder,
- EmbedBuilder,
- ActionRowBuilder,
- ButtonBuilder,
- ButtonStyle,
- ComponentType,
- StringSelectMenuBuilder,
- TextInputBuilder,
- TextInputStyle,
- PermissionFlagsBits,
- ChannelType,
- } = require('discord.js');
- const gamesData = require('../../Templates/gameTMP.json'); // Adjust the path if necessary
- const { getLanguage } = require('../../Utils/getLanguage');
- module.exports = {
- data: new SlashCommandBuilder()
- .setName('create_event')
- .setDescription('📅 Create a new event step by step.'),
- /**
- * Executes the command logic.
- * @param {ChatInputCommandInteraction} interaction
- * @param {Client} client
- */
- async execute(interaction, client) {
- await interaction.deferReply({ ephemeral: true });
- const { user, guild } = interaction;
- const translations = await getLanguage(interaction, true);
- // Notify user to check DMs
- const notificationEmbed = new EmbedBuilder()
- .setTitle('Event Creation')
- .setDescription('Check your DMs to start creating your event! 📩')
- .setColor('Aqua');
- await interaction.editReply({ embeds: [notificationEmbed] });
- try {
- const dmChannel = await user.createDM();
- // Ask for event type
- const eventTypeEmbed = new EmbedBuilder()
- .setTitle('Choose Event Type')
- .setDescription(
- 'Please select the type of event you want to create from the options below:'
- )
- .addFields(
- {
- name: '🎮 Gaming',
- value: 'Events related to games like WoW, FFXIV, etc.',
- },
- { name: '📊 General Polls', value: 'Surveys or voting events.' },
- { name: '🛠 Custom Events', value: 'Create a fully custom event.' }
- )
- .setColor('Blue')
- .setFooter({
- text: 'Select an option to proceed.',
- iconURL: user.displayAvatarURL(),
- })
- .setTimestamp();
- const eventTypeButtons = new ActionRowBuilder().addComponents(
- new ButtonBuilder()
- .setCustomId('gaming_event')
- .setLabel('🎮 Gaming')
- .setStyle(ButtonStyle.Primary),
- new ButtonBuilder()
- .setCustomId('general_poll')
- .setLabel('📊 General Poll')
- .setStyle(ButtonStyle.Secondary),
- new ButtonBuilder()
- .setCustomId('custom_event')
- .setLabel('🛠 Custom Event')
- .setStyle(ButtonStyle.Success)
- );
- await dmChannel.send({
- embeds: [eventTypeEmbed],
- components: [eventTypeButtons],
- });
- const collector = dmChannel.createMessageComponentCollector({
- filter: (interaction) =>
- interaction.customId === 'gaming_event' ||
- interaction.customId === 'general_poll' ||
- interaction.customId === 'custom_event',
- componentType: ComponentType.Button,
- idle: 60000,
- });
- const variableData = {
- Type: '',
- templateID: '',
- Title: '',
- Description: '',
- Date: '',
- Time: '',
- Channel: '',
- };
- collector.on('collect', async (buttonInteraction) => {
- await buttonInteraction.deferUpdate();
- let responseEmbed;
- if (buttonInteraction.customId === 'gaming_event') {
- // Prepare game list for dropdown
- variableData.Type = 'Gaming'; // Save type
- const gameOptions = gamesData.map((game) => ({
- emoji: `${game.templateEmoji}`,
- label: `${game.templateID} - ${game.templateName}`,
- value: `${game.templateID}`,
- }));
- // Show game selection dropdown
- responseEmbed = new EmbedBuilder()
- .setTitle('Gaming Event Selected')
- .setDescription(
- 'You chose **Gaming**. Select a game from the list below:'
- )
- .setColor('Green');
- // Add game list as fields in the embed
- gamesData.forEach((game) => {
- responseEmbed.addFields({
- name: `\u200B`,
- value: `**${game.templateID}** - ${game.templateEmoji} ${game.templateName}`, // Add other details if needed
- inline: true, // Optional: display fields inline
- });
- });
- const selectMenu = new ActionRowBuilder().addComponents(
- new StringSelectMenuBuilder()
- .setCustomId('game_select')
- .setPlaceholder('Choose your game')
- .addOptions(gameOptions)
- );
- await dmChannel.send({
- embeds: [responseEmbed],
- components: [selectMenu],
- });
- } else if (buttonInteraction.customId === 'general_poll') {
- responseEmbed = new EmbedBuilder()
- .setTitle('General Poll Selected')
- .setDescription(
- 'You chose **General Poll**. Let’s set up your poll questions and options.'
- )
- .setColor('Green');
- } else if (buttonInteraction.customId === 'custom_event') {
- responseEmbed = new EmbedBuilder()
- .setTitle('Custom Event Selected')
- .setDescription(
- 'You chose **Custom Event**. Let’s build your custom event step by step.'
- )
- .setColor('Green');
- }
- collector.stop(); // Proceed to the next steps based on the selection
- const templateCollector = dmChannel.createMessageComponentCollector({
- componentType: ComponentType.StringSelect,
- idle: 60000,
- });
- templateCollector.on('collect', async (dropDownInteraction) => {
- await dropDownInteraction.deferReply();
- variableData.templateID = dropDownInteraction.values[0];
- templateCollector.stop();
- const titleEmbed = new EmbedBuilder()
- .setTitle('Event Title')
- .setDescription(
- 'Please provide a title for your event. Respond with your desired title below.'
- )
- .setColor('Blue');
- await dropDownInteraction.followUp({ embeds: [titleEmbed] });
- const titleCollector = dmChannel.createMessageCollector({
- filter: (m) =>
- m.author.id === user.id && m.channel.id === dmChannel.id,
- idle: 60000,
- max: 1,
- });
- titleCollector.on('collect', async (message) => {
- variableData.Title = message.content;
- titleCollector.stop();
- const descriptionEmbed = new EmbedBuilder()
- .setTitle('Event Description')
- .setDescription(
- 'Please provide a description for your event. Respond with your desired description below.'
- )
- .setColor('Blue');
- await dmChannel.send({ embeds: [descriptionEmbed] });
- const descriptionCollector = dmChannel.createMessageCollector({
- filter: (m) =>
- m.author.id === user.id && m.channel.id === dmChannel.id,
- idle: 60000,
- max: 1,
- });
- descriptionCollector.on('collect', async (message) => {
- variableData.Description = message.content;
- descriptionCollector.stop();
- const dateEmbed = new EmbedBuilder()
- .setTitle('Event Date')
- .setDescription(
- 'Please provide a date for your event.\n\n' +
- '**Format:** `YYYY-MM-DD`\n' +
- '**Example:** `2024-12-31`\n\n' +
- 'Type your date below to proceed.'
- )
- .setColor('Blue')
- .setFooter({
- text: 'Ensure the format is correct to avoid errors.',
- })
- .setTimestamp();
- await dmChannel.send({ embeds: [dateEmbed] });
- const dateCollector = dmChannel.createMessageCollector({
- filter: (m) =>
- m.author.id === user.id && m.channel.id === dmChannel.id,
- idle: 60000,
- });
- dateCollector.on('collect', async (message) => {
- const userInput = message.content;
- variableData.Date = userInput;
- const dateRegex = /^\d{4}-\d{2}-\d{2}$/;
- if (!dateRegex.test(userInput)) {
- const errorEmbed = new EmbedBuilder()
- .setTitle('Invalid Date Format')
- .setDescription(
- 'The date you provided is not in the correct format.\n' +
- '**Expected Format:** `YYYY-MM-DD`\n' +
- '**Example:** `2024-12-31`\n\n' +
- 'Please try again.'
- )
- .setColor('Red');
- await dmChannel.send({ embeds: [errorEmbed] });
- return;
- }
- const [year, month, day] = userInput.split('-').map(Number);
- const daysInMonth = new Date(year, month, 0).getDate();
- if (month < 1 || month > 12 || day < 1 || day > daysInMonth) {
- const errorEmbed = new EmbedBuilder()
- .setTitle('Invalid Date')
- .setDescription(
- `The date you provided is not valid.\n` +
- `**Month Range:** 1-12\n` +
- `**Day Range:** 1-${daysInMonth} (for ${month}/${year})\n\n` +
- `Please try again.`
- )
- .setColor('Red');
- await dmChannel.send({ embeds: [errorEmbed] });
- return;
- }
- dateCollector.stop();
- const botTimeZone =
- Intl.DateTimeFormat().resolvedOptions().timeZone; // Bot's timezone
- const now = new Date();
- const botTime = now.toLocaleTimeString('en-US', {
- timeZone: botTimeZone,
- hour12: false,
- hour: '2-digit',
- minute: '2-digit',
- });
- const timeEmbed = new EmbedBuilder()
- .setTitle('Event Time')
- .setDescription(
- `Please provide the time for your event in **24-hour format**.\n\n` +
- `**Example Format:** \`18:15\`\n\n` +
- `**Current Server Time:**\n` +
- `> 🕒 ${botTime} (${botTimeZone})\n\n` +
- `*Note: To change the servers's timezone, adjust your server settings.*`
- )
- .setColor('Blue');
- await dmChannel.send({ embeds: [timeEmbed] });
- const timeCollector = dmChannel.createMessageCollector({
- filter: (m) =>
- m.author.id === user.id && m.channel.id === dmChannel.id,
- idle: 60000,
- });
- timeCollector.on('collect', async (message) => {
- const timeInput = message.content.trim();
- const timeRegex = /^([01]?\d|2[0-3]):([0-5]\d)$/;
- if (!timeRegex.test(timeInput)) {
- const errorEmbed = new EmbedBuilder()
- .setTitle('Invalid Time Format')
- .setDescription(
- '❌ The time you entered is invalid. Please use the **24-hour format**, e.g., `18:15`.\n\n' +
- '**Example:**\n`18:15`'
- )
- .setColor('Red');
- dmChannel.send({ embeds: [errorEmbed] });
- return;
- }
- variableData.Time = timeInput;
- timeCollector.stop();
- const channelEmbed = new EmbedBuilder()
- .setTitle('Select Event Channel')
- .setDescription(
- 'Please choose a channel for your event to take place in. Select from the options below:'
- )
- .setColor('Blue');
- const textChannels = [];
- const forumChannels = [];
- const threadChannels = [];
- const allChannels = await guild.channels.cache.filter(
- (channel) => {
- const userHasPermission =
- channel
- .permissionsFor(user)
- .has(PermissionFlagsBits.ViewChannel) &&
- channel
- .permissionsFor(user)
- .has(PermissionFlagsBits.SendMessages);
- const botHasPermission =
- channel
- .permissionsFor(guild.members.me)
- .has(PermissionFlagsBits.ViewChannel) &&
- channel
- .permissionsFor(guild.members.me)
- .has(PermissionFlagsBits.SendMessages);
- return userHasPermission && botHasPermission;
- }
- );
- allChannels.forEach((channel) => {
- if (channel.type === ChannelType.GuildForum) {
- forumChannels.push(channel);
- } else if (channel.isThread()) {
- threadChannels.push(channel);
- } else if (channel.type === ChannelType.GuildText) {
- textChannels.push(channel);
- }
- });
- const createChannelDropdown = (channels, placeholder) => {
- const options = channels.map((channel) => ({
- label: channel.name,
- value: channel.id,
- }));
- const dropdowns = [];
- for (let i = 0; i < options.length; i += 25) {
- const chunk = options.slice(i, i + 25);
- const selectMenu = new StringSelectMenuBuilder()
- .setCustomId(placeholder.toLowerCase() + '_select')
- .setPlaceholder(`Choose a ${placeholder} channel`)
- .addOptions(chunk);
- dropdowns.push(
- new ActionRowBuilder().addComponents(selectMenu)
- );
- }
- return dropdowns;
- };
- const components = [];
- if (forumChannels.length > 0) {
- channelEmbed.addFields({
- name: `Forum Channels (${forumChannels.length})`,
- value: 'Select a forum channel for your event',
- });
- components.push(
- ...createChannelDropdown(forumChannels, 'Forum')
- );
- }
- if (textChannels.length > 0) {
- channelEmbed.addFields({
- name: `Text Channels (${textChannels.length})`,
- value: 'Select a text channel for your event',
- });
- components.push(
- ...createChannelDropdown(textChannels, 'Text')
- );
- }
- if (threadChannels.length > 0) {
- channelEmbed.addFields({
- name: `Thread Channels (${threadChannels.length})`,
- value: 'Select a thread channel for your event',
- });
- components.push(
- ...createChannelDropdown(threadChannels, 'Thread')
- );
- }
- await dmChannel.send({
- embeds: [channelEmbed],
- components: components.length ? components : [],
- });
- const channelCollector =
- dmChannel.createMessageComponentCollector({
- filter: (interaction) =>
- interaction.customId.endsWith('_select'),
- componentType: ComponentType.StringSelect,
- idle: 60000,
- });
- channelCollector.on('collect', async (interaction) => {
- await interaction.deferUpdate();
- variableData.Channel = interaction.values[0];
- const selectedChannelId = interaction.values[0];
- const selectedChannel = await guild.channels.fetch(
- selectedChannelId
- );
- const confirmationEmbed = new EmbedBuilder()
- .setTitle('Channel Selected')
- .setDescription(
- `You selected the channel **${selectedChannel.name}** for your event.`
- )
- .setColor('Green');
- await interaction.followUp({
- embeds: [confirmationEmbed],
- });
- channelCollector.stop();
- await dmChannel.send({
- content:
- `Here are the details of your event:\n\n` +
- `**Event Type:** ${variableData.Type}\n` +
- `**Template ID:** ${variableData.templateID}\n` +
- `**Title:** ${variableData.Title}\n` +
- `**Description:** ${variableData.Description}\n` +
- `**Date:** ${variableData.Date}\n` +
- `**Channel:** ${selectedChannel.name}`,
- });
- });
- channelCollector.on('end', (_, reason) => {
- if (reason === 'time') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription(
- 'You took too long to respond. Please try again.'
- )
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- });
- timeCollector.on('end', (_, reason) => {
- if (reason === 'idle') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription(
- 'You took too long to respond. Please try again.'
- )
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- });
- });
- descriptionCollector.on('end', (_, reason) => {
- if (reason === 'idle') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription(
- 'You took too long to respond. Please try again.'
- )
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- });
- titleCollector.on('end', (_, reason) => {
- if (reason === 'idle') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription(
- 'You took too long to respond. Please try again.'
- )
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- });
- templateCollector.on('end', (_, reason) => {
- if (reason === 'idle') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription('You took too long to respond. Please try again.')
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- });
- collector.on('end', (_, reason) => {
- if (reason === 'idle') {
- const timeoutEmbed = new EmbedBuilder()
- .setTitle('Session Expired')
- .setDescription('You took too long to respond. Please try again.')
- .setColor('Red');
- dmChannel.send({ embeds: [timeoutEmbed] });
- }
- });
- } catch (error) {
- const errorEmbed = new EmbedBuilder()
- .setTitle('Error')
- .setDescription(
- 'I was unable to send you a DM. Please check your settings and try again.'
- )
- .setColor('Red');
- await interaction.editReply({ embeds: [errorEmbed] });
- }
- },
- };
Advertisement
Add Comment
Please, Sign In to add comment