const { Events, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, StringSelectMenuOptionBuilder, StringSelectMenuBuilder, ComponentType } = require("discord.js"); module.exports = { name: Events.InteractionCreate, async execute(client, interaction) { if (interaction.customId === "deployServer") { await interaction.deferUpdate(); const selectedServer = await interaction.client.db.get( `ashServers.${interaction.user.id}.selectedServer` ); const continentSelect = new EmbedBuilder() .setDescription( `## ${selectedServer}\nPlease choose a continent to host from the dropdown below. The closer you are to the server, the lower your ping will be.` ) .setColor("#2b2d31") .setFooter({ text: "Powered by ASH | Assetto Server Hosting", iconURL: client.user.avatarURL() }); const uniqueContinents = [ ...new Set( (await client.db.get("regions")).regions.map( (region) => region.continent ) ) ]; let continentOptions = uniqueContinents.map((x) => { return new StringSelectMenuOptionBuilder() .setLabel(x) .setValue(x); }); const continentSelectMenu = new StringSelectMenuBuilder() .setCustomId("continentSelect") .setPlaceholder("Select a continent") .addOptions(continentOptions); const row = new ActionRowBuilder().addComponents( continentSelectMenu ); let continentResponse = await interaction.editReply({ fetchReply: true, embeds: [continentSelect], ephemeral: true, components: [row] }); const collector = continentResponse.createMessageComponentCollector( { componentType: ComponentType.StringSelect, time: 6e4 * 2 } ); collector.once("collect", async (i) => { const continentSelection = i.values[0]; console.log(continentSelection); const citySelect = new EmbedBuilder() .setDescription( `## ${selectedServer}\nContinent: \`${continentSelection}\`\nPlease choose the city your server belongs.` ) .setColor("#2b2d31") .setFooter({ text: "Powered by ASH | Assetto Server Hosting", iconURL: client.user.avatarURL() }); const uniqueCities = [ ...new Set( (await client.db.get("regions")).regions .filter((x) => x.continent === continentSelection) .map((region) => region.city) ) ]; //console.log(uniqueCities); let cityOptions = uniqueCities.map((x) => { return new StringSelectMenuOptionBuilder() .setLabel(x) .setValue(x); }); //console.log(cityOptions); const citySelectMenu = new StringSelectMenuBuilder() .setCustomId("citySelect") .setPlaceholder("Select a city") .addOptions(cityOptions); const row = new ActionRowBuilder().addComponents( citySelectMenu ); await i.deferUpdate(); let cityResponse = await interaction.editReply({ embeds: [citySelect], ephemeral: true, components: [row] }); const collector = cityResponse.createMessageComponentCollector({ componentType: ComponentType.StringSelect, time: 6e4 * 2 }); collector.once("collect", async (i) => { const citySelection = i.values[0]; await i.deferUpdate(); const selectedServerQuery = await interaction.client.db.get( `ashServers.${interaction.user.id}.servers` ); const selectedServer = await interaction.client.db.get( `ashServers.${interaction.user.id}.selectedServer` ); const selectedServerInfo = selectedServerQuery.find( (server) => server.nickname === selectedServer ); const confirmServerLocation = new EmbedBuilder() .setDescription( `## ${selectedServer}\n**Please confirm your host location:**\nContinent: \`${continentSelection}\`\nCity: \`${citySelection}\`` ) .setColor("#2b2d31") .setFooter({ text: "Powered by ASH | Assetto Server Hosting", iconURL: client.user.avatarURL() }); selectedServerInfo.location.continent = continentSelection; selectedServerInfo.location.city = citySelection; await interaction.client.db.set( `ashServers.${interaction.user.id}.servers`, selectedServerQuery ); const row = [ new ActionRowBuilder().addComponents( new ButtonBuilder() .setCustomId("confirmDeploy") .setLabel("Confirm Deploy") .setStyle(ButtonStyle.Success), new ButtonBuilder() .setCustomId("cancelDeploy") .setLabel("Cancel Deploy") .setStyle(ButtonStyle.Danger) ) ]; await interaction.editReply({ embeds: [confirmServerLocation], ephemeral: true, components: [...row] }); }); }); } } };