Untitled
unknown
javascript
2 years ago
3.3 kB
2
Indexable
Never
const { Client, Intents } = require('discord.js'); const client = new Client({ intents: [Intents.FLAGS.GUILDS] }); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('interactionCreate', async (interaction) => { if (!interaction.isCommand() || interaction.commandName !== 'rain') return; await interaction.deferReply({ ephemeral: true }); // acknowledge command receipt // create the modal with a ChannelSelectMenu field const modal = { type: 'modal', title: 'Rain settings', content: { type: 'application/json', data: { embeds: [{ title: 'Configure rain settings', description: 'Please fill out the fields below:', fields: [ { name: 'How much rain?', type: 2, // number field placeholder: 'Enter the amount of rain', }, { name: 'How many winners?', type: 2, // number field placeholder: 'Enter the number of winners', }, { name: 'How much time will the rain be?', type: 2, // number field placeholder: 'Enter the duration of rain (in seconds)', }, { name: 'What channel?', type: 3, // channel select menu field options: interaction.guild.channels.cache.filter((channel) => channel.type === 'GUILD_TEXT').map((channel) => ({ label: channel.name, value: channel.id, })), }, { name: 'Who is raining?', type: 6, // user select menu field placeholder: 'Select the user who will rain', }, ], }], }, }, actions: [ { type: 'button', label: 'Submit', style: 1, // primary button style custom_id: 'rain_submit', }, { type: 'button', label: 'Cancel', style: 2, // secondary button style custom_id: 'rain_cancel', }, ], }; // send the modal to the user who invoked the command await interaction.followUp({ content: 'Please fill out the rain settings:', components: [modal] }); }); client.on('interactionCreate', async (interaction) => { if (!interaction.isButton()) return; if (interaction.customId === 'rain_cancel') { // delete the modal if the user clicks the cancel button await interaction.update({ content: 'Rain settings cancelled.', components: [] }); } else if (interaction.customId === 'rain_submit') { // get the values of the fields from the modal const rainAmount = interaction.message.interaction.content.data.embeds[0].fields[0].value; const winnerCount = interaction.message.interaction.content.data.embeds[0].fields[1].value; const rainDuration = interaction.message.interaction.content.data.embeds[0].fields[2].value; const channel = interaction.guild.channels.cache.get(interaction.message.interaction.content.data.embeds[0].fields[3].options[0].value); const rainer = interaction.message.interaction.content.data.embeds[0].fields[4].options[0].value; // do something with the rain settings (e.g. send a message to the selected channel) const winners