Gbrad
Gbrad
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
Constructive criticism is my favorite so thank you @duck for making me rethink my work.
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
The fix was that the const filter is a function and then (currentInteraction) is an inline function itself that takes in one parameter and this is declared as currentInteraction. Now the method looks at the parameter's customId and checks it against the id set at the top of the class.
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
Okay I owe you a thank you. This was a skill issue. I'm new to JS so I was being a bonehead and just trying to use arrow syntax functions without truly knowing what they do. Here are my changes
modal.addComponents(firstActionRow, secondActionRow, thirdActionRow, fourthActionRow, fifthActionRow);

await interaction.showModal(modal);

// wait for the modal to be submitted
const filter = (currentInteraction) => currentInteraction.customId === `myModal-${interaction.id}`;

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}`);
});
},
modal.addComponents(firstActionRow, secondActionRow, thirdActionRow, fourthActionRow, fifthActionRow);

await interaction.showModal(modal);

// wait for the modal to be submitted
const filter = (currentInteraction) => currentInteraction.customId === `myModal-${interaction.id}`;

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}`);
});
},
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
let me mess around with it a bit
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
does that not look at the current interaction?
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
hmmmm
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
New issue when I try this though. The modal won't submit.
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
new code
const { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('record')
.setDescription('Records game details.'),
category: 'mtg',
async execute(interaction) {
const modal = new ModalBuilder({
customId: `myModal-${interaction.id}`,
title: 'Game Summary',
});

// question 1
const whoPlayedInTheGameInput = new TextInputBuilder({
customId: 'whoPlayedInTheGameInput',
label: 'Who played in the game?',
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.id}`;

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}`);
});
},
};
const { ActionRowBuilder, ModalBuilder, TextInputBuilder, TextInputStyle, SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('record')
.setDescription('Records game details.'),
category: 'mtg',
async execute(interaction) {
const modal = new ModalBuilder({
customId: `myModal-${interaction.id}`,
title: 'Game Summary',
});

// question 1
const whoPlayedInTheGameInput = new TextInputBuilder({
customId: 'whoPlayedInTheGameInput',
label: 'Who played in the game?',
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.id}`;

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}`);
});
},
};
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
Yes one moment please
16 replies
DIAdiscord.js - Imagine an app
Created by Gbrad on 4/24/2024 in #djs-questions
Unique Id on modal crashing bot submission after cancel
Okay so I tried this and it still doesn’t work. I changed the custom id to ‘my-modal-${interaction.Id}’
16 replies