const { Client, Intents, MessageEmbed } = require('discord.js');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { ModalBuilder, TextInputBuilder, TextInputStyle, MessageActionRow } = require('discord-buttons');
const clientId = '11';
const guildId = '11';
const commands = [
{
name: 'ping',
description: 'Replies with Pong!'
},
{
name: 'saay',
description: 'ffff!'
},
];
const client = new Client({
intents: [
Intents.FLAGS.GUILDS,
Intents.FLAGS.GUILD_MESSAGES,
Intents.FLAGS.MESSAGE_CONTENT,
],
});
const commandsRest = new REST({ version: '9' }).setToken('MTE4Mj');
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand()) return;
if (interaction.commandName === 'saay') {
const modal = new ModalBuilder()
.setCustomId('myModal')
.setTitle('Say Modal');
const favoriteColorInput = new TextInputBuilder()
.setCustomId('favoriteColorInput')
.setLabel("Please enter your message below.")
.setStyle(TextInputStyle.Short);
const hobbiesInput = new TextInputBuilder()
.setCustomId('hobbiesInput')
.setLabel("What's some of your favorite hobbies?")
.setStyle(TextInputStyle.Paragraph);
const firstActionRow = new MessageActionRow().addComponents(favoriteColorInput);
const secondActionRow = new MessageActionRow().addComponents(hobbiesInput);
modal.addComponents(firstActionRow, secondActionRow);
const reply = await interaction.reply({ content: 'Say something:', components: [modal], fetchReply: true });
const collector = interaction.channel.createMessageComponentCollector({
filter: i => i.isMessageComponent() && i.customId === 'myModal' && i.message.id === reply.id,
time: 30000, // Adjust the time limit as needed
});
collector.on('collect', async i => {
const firstInput = i.values[0]; // Value from the firstActionRow
const secondInput = i.values[1]; // Value from the secondActionRow
const embed = new MessageEmbed()
.setColor('#00ff00')
.setTitle('Modal Builder Result')
.addField('Favorite Color:', firstInput)
.addField('Favorite Hobbies:', secondInput);
await interaction.followUp({ embeds: [embed] });
});
collector.on('end', collected => {
if (collected.size === 0) {
interaction.followUp('You did not provide the required input. The command has been canceled.');
}
});
}
});
(async () => {
console.log('Started refreshing application (/) commands.');
try {
await commandsRest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
});
client.login('MTE4Mj')