const { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, SlashCommandBuilder } = require('discord.js');
let randomNumber = Math.floor(Math.random() * 10000);
module.exports = {
data: new SlashCommandBuilder()
.setName('record')
.setDescription('Records game details.'),
category: 'mtg',
async execute(interaction) {
const modal = new ModalBuilder({
customId: `myModal-${interaction.user.id}-${randomNumber}`,
title: 'Game Summary',
});
// question 1
const whoPlayedInTheGameInput = new TextInputBuilder({
customId: 'whoPlayedInTheGameInput',
label: 'Who played in the game?',
style: TextInputStyle.Short,
});
// question 2
const gameFormatInput = new TextInputBuilder({
customId: 'gameFormatInput',
label: 'What was the game format?',
style: TextInputStyle.Short,
});
...
...
// set rows for the modal
const firstActionRow = new ActionRowBuilder().addComponents(whoPlayedInTheGameInput);
const secondActionRow = new ActionRowBuilder().addComponents(gameFormatInput);
const thirdActionRow = new ActionRowBuilder().addComponents(whoWonTheGameInput);
const fourthActionRow = new ActionRowBuilder().addComponents(howLongWasTheGameInput);
const fifthActionRow = new ActionRowBuilder().addComponents(matchHighlightInput);
modal.addComponents(firstActionRow, secondActionRow, thirdActionRow, fourthActionRow, fifthActionRow);
await interaction.showModal(modal);
// wait for the modal to be submitted
const filter = (interaction) => interaction.customId === `myModal-${interaction.user.id}-${randomNumber}`;
interaction
.awaitModalSubmit({ filter, time: 60_000 })
.then((modalInteraction) => {
const whoPlayedInTheGameInputValue = modalInteraction.fields.getTextInputValue('whoPlayedInTheGameInput');
const gameFormatInputValue = modalInteraction.fields.getTextInputValue('gameFormatInput');
const whoWonTheGameInputValue = modalInteraction.fields.getTextInputValue('whoWonTheGameInput');
const howLongWasTheGameInputValue = modalInteraction.fields.getTextInputValue('howLongWasTheGameInput');
const matchHighlightInputValue = modalInteraction.fields.getTextInputValue('matchHighlightInput');
const output = `Players: ${whoPlayedInTheGameInputValue}\nFormat: ${gameFormatInputValue}\nWinner: ${whoWonTheGameInputValue}\nMatch Time: ${howLongWasTheGameInputValue}\nMatch Highlight: ${matchHighlightInputValue}`;
modalInteraction.reply(output);
console.log(`----- ${interaction.user.username} successfully created a record -----\n${output}`);
})
.catch((err) => {
console.log(`Error: ${err}`);
});
},
};