Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- async function handleCreateScrim(interaction) {
- if (!interaction.member.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
- await interaction.reply({ content: 'You do not have MANAGE_GUILD permission to use this command.', ephemeral: true });
- return;
- }
- const registrationChannel = interaction.options.getChannel('registration_channel');
- const slotListChannel = interaction.options.getChannel('slotlist_channel');
- const successRole = interaction.options.getRole('success_role');
- const requiredMentions = interaction.options.getInteger('required_mentions');
- const totalSlots = interaction.options.getInteger('total_slots');
- const openTime = interaction.options.getString('open_time');
- // Check if the channels are already in use
- const existingScrim = Object.values(scrimSettings).find(settings =>
- settings.registrationChannelId === registrationChannel.id ||
- settings.slotListChannelId === slotListChannel.id
- );
- if (existingScrim) {
- await interaction.reply({
- content: 'This channel is already set up for another scrim. Please delete the existing scrim before setting up a new one.',
- ephemeral: true
- });
- return;
- }
- if (!registrationChannel.isTextBased() || !slotListChannel.isTextBased()) {
- await interaction.reply({ content: 'Both the registration and slotlist channels must be text channels.', ephemeral: true });
- return;
- }
- const botRole = interaction.guild.members.me.roles.highest;
- if (successRole.position >= botRole.position) {
- await interaction.reply({ content: 'The success role must be lower in position than the bot\'s highest role.', ephemeral: true });
- return;
- }
- if (requiredMentions < 1 || requiredMentions > 4 || totalSlots < 1 || totalSlots > 25) {
- await interaction.reply({ content: 'Required mentions must be between 1 and 4, and total slots must be between 1 and 25.', ephemeral: true });
- return;
- }
- const timeParts = openTime.split(':');
- if (timeParts.length !== 2 || isNaN(timeParts[0]) || isNaN(timeParts[1]) ||
- timeParts[0] < 0 || timeParts[0] > 23 || timeParts[1] < 0 || timeParts[1] > 59) {
- await interaction.reply({ content: 'Open time must be in 24-hour format (HH:MM).', ephemeral: true });
- return;
- }
- const now = new Date();
- const openDateTime = new Date(now.getFullYear(), now.getMonth(), now.getDate(), timeParts[0], timeParts[1], 0);
- if (openDateTime <= now) {
- openDateTime.setDate(openDateTime.getDate() + 1); // Schedule for next day if time has already passed
- }
- const delay = openDateTime - now;
- scrimSettings[interaction.guildId] = {
- registrationChannelId: registrationChannel.id,
- slotListChannelId: slotListChannel.id,
- successRoleId: successRole.id,
- requiredMentions,
- totalSlots,
- filledSlots: 0,
- confirmedUsers: []
- };
- saveScrimSettings(scrimSettings); // Save scrim settings to file
- setTimeout(async () => {
- const settings = scrimSettings[interaction.guildId];
- if (!settings) return;
- const registrationChannel = interaction.guild.channels.cache.get(settings.registrationChannelId);
- const slotListChannel = interaction.guild.channels.cache.get(settings.slotListChannelId);
- // Open registration channel
- await registrationChannel.permissionOverwrites.edit(interaction.guild.roles.everyone, {
- [PermissionsBitField.Flags.SendMessages]: true
- });
- const registrationStartTime = Date.now(); // Store the start time
- const embed = new EmbedBuilder()
- .setTitle('Registration is now open!')
- .setDescription(`:mega: ${settings.requiredMentions} mentions required.\n:mega: Total slots: ${settings.totalSlots}`)
- .setColor('#0099ff')
- .setTimestamp();
- await registrationChannel.send({ embeds: [embed] });
- const collector = registrationChannel.createMessageCollector({ filter: (m) => !m.author.bot, time: 3600000 }); // 1 hour duration
- collector.on('collect', async (message) => {
- if (message.author.bot) return; // Ignore messages from bots
- const mentions = message.mentions.users.filter(user => !user.bot).map(user => user.username); // Array of mentioned users
- // Check if enough users were mentioned
- if (mentions.length < settings.requiredMentions) {
- await message.react('❌');
- } else {
- await message.react('✅');
- await message.member.roles.add(settings.successRoleId);
- settings.confirmedUsers.push({
- username: message.author.username,
- userId: message.author.id, // Store user ID for mentioning
- mentions, // Store the actual mentioned users
- messageId: message.id // Store the message ID for redirect
- });
- settings.filledSlots++;
- if (settings.filledSlots >= settings.totalSlots) {
- collector.stop();
- }
- }
- });
- collector.on('end', async () => {
- const registrationDuration = Date.now() - registrationStartTime; // Duration in milliseconds
- const durationInSeconds = Math.floor(registrationDuration / 1000); // Convert to seconds
- // Notify all slots filled in the registration channel
- const filledEmbed = new EmbedBuilder()
- .setTitle('Registration is now closed.')
- .setColor('#0099ff');
- await registrationChannel.send({ embeds: [filledEmbed] });
- const numberedList = settings.confirmedUsers.map((user, index) => `Slot ${index + 1} -> ${user.username}'s Team`).join('\n');
- const embed = new EmbedBuilder()
- .setTitle('Manager-Scrims Slotlist')
- .setDescription(`\`\`\`\n${numberedList}\n\`\`\``)
- .setColor('#0099ff')
- .setFooter({
- text: `Registration took ${durationInSeconds} seconds`,
- iconURL: client.user.displayAvatarURL() // Add bot's avatar
- });
- // Send the embed and the Info button
- const infoButton = new ButtonBuilder()
- .setCustomId('info_button')
- .setLabel('Info ❓') // Add the question mark emoji here
- .setStyle(ButtonStyle.Primary);
- const row = new ActionRowBuilder().addComponents(infoButton);
- await slotListChannel.send({
- embeds: [embed],
- components: [row] // Add the button
- });
- // Button interaction listener
- const buttonCollector = slotListChannel.createMessageComponentCollector({
- componentType: ComponentType.Button,
- time: 3600000, // 1 hour
- filter: (i) => i.customId === 'info_button'
- });
- buttonCollector.on('collect', async (buttonInteraction) => {
- if (buttonInteraction.customId === 'info_button') {
- // Check if the user has the ManageGuild permission
- if (!buttonInteraction.member.permissions.has(PermissionsBitField.Flags.ManageGuild)) {
- await buttonInteraction.reply({
- content: 'You do not have MANAGE_GUILD permission to use this button.',
- ephemeral: true
- });
- return;
- }
- // Generate the select menu options based on the filled slots
- const selectMenu = new SelectMenuBuilder()
- .setCustomId('slot_info_menu')
- .setPlaceholder('Choose a slot to view details')
- .addOptions(
- settings.confirmedUsers.map((user, index) => ({
- label: `Slot ${index + 1}`,
- value: `slot_${index + 1}`
- }))
- );
- const menuRow = new ActionRowBuilder().addComponents(selectMenu);
- await buttonInteraction.reply({
- content: 'Select a slot from the dropdown menu to view more information:',
- components: [menuRow],
- ephemeral: true
- });
- }
- });
- // Create a select menu collector to handle slot selection
- const menuCollector = slotListChannel.createMessageComponentCollector({
- componentType: ComponentType.SelectMenu,
- time: 3600000, // 1 hour
- filter: (i) => i.customId === 'slot_info_menu'
- });
- menuCollector.on('collect', async (menuInteraction) => {
- const selectedValue = menuInteraction.values[0];
- const slotNumber = parseInt(selectedValue.split('_')[1], 10); // Extract slot number
- // Get the details of the selected slot
- const slotDetails = settings.confirmedUsers[slotNumber - 1];
- const mentionedUsers = slotDetails.mentions.join(', '); // Join the mentions into a string
- const originalMessageLink = `https://discord.com/channels/${interaction.guild.id}/${settings.registrationChannelId}/${slotDetails.messageId}`;
- const registeredBy = `<@${slotDetails.userId}>`;
- // Build and send the info embed
- const infoEmbed = new EmbedBuilder()
- .setTitle(`Slot Info`)
- .setDescription(`**Slot No:** \`${slotNumber}\`\n**Name**: \`${slotDetails.username}'s Team\`\n**Captain:** ${slotDetails.username} (<@${slotDetails.userId}>)\n**Team:** ${mentionedUsers}\n**Registration Message**\n[Jump to Message](${originalMessageLink})`)
- .setColor('#0099ff');
- await menuInteraction.reply({
- embeds: [infoEmbed],
- ephemeral: true
- });
- });
- await registrationChannel.permissionOverwrites.edit(interaction.guild.roles.everyone, {
- [PermissionsBitField.Flags.SendMessages]: false
- });
- delete scrimSettings[interaction.guildId];
- saveScrimSettings(scrimSettings); // Save updated settings
- });
- }, delay);
- await interaction.reply({
- content: `Scrim setup successful! Here are the details:
- Registration Channel: #${registrationChannel.name}
- Slot List Channel: #${slotListChannel.name}
- Success Role: @${successRole.name}
- Required Mentions: ${requiredMentions}
- Total Slots: ${totalSlots}
- Registration Opens At: ${openTime}`, ephemeral: true });
- }
Add Comment
Please, Sign In to add comment