Follow up response

Im attempting to get the response of a follow up, after a slash command and a button click Basically want a ban button and after they press that to get the reason for ban. I attached a snipped of where it goes wrong (after the collection)
No description
9 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
connor
connor3mo ago
discord.js@14.14.1
discord.js@14.14.1
v18.15.0
v18.15.0
d.js docs
d.js docs3mo ago
To share long code snippets, use a service like gist, sourcebin, starbin, or similar instead of posting them as large code blocks or files.
connor
connor3mo ago
async execute(interaction) {
try {
const message = interaction.options.getString("input");

const results = await cloud.getUsersData(message);
const data = await sendUser(interaction, message, results);
const response = await interaction.reply({ embeds: [data.embed], components: [data.row] });
const collectorFilter = i => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("confirmation=", confirmation.customId)
if (confirmation.customId == 'ban') {

await interaction.followUp({ content: 'Please enter your reason:', ephemeral: true });

const filter = m => m.author.id === interaction.user.id; // Collect messages only from the user who interacted
const collector = interaction.channel.createMessageCollector({ filter, max: 1, time: 60000 }); // Adjust time as needed
collector.on('collect', m => {
console.log(`Collected message: ${m.content}`);
// Process the response
// For example, implementing your ban logic here
});

cloud.editData(message, "Bans", 1)
console.log(interaction, "person")
const channel = interaction.client.channels.cache.get(gameInfo.test.log_channel);
const logmsg = `${interaction.user.username} banned user ${message}`
channel.send(logmsg)
await confirmation.update({ content: `${message} has been banned for reason`, components: [] });
} else if (confirmation.customId === 'cancel') {
await confirmation.update({ content: 'Action cancelled', components: [] });
}
} catch (e) {
console.error(e)
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

} catch (error) {
console.error(error);
await interaction.reply({ content: 'Failed to find user', ephemeral: true });
}
},
},
async execute(interaction) {
try {
const message = interaction.options.getString("input");

const results = await cloud.getUsersData(message);
const data = await sendUser(interaction, message, results);
const response = await interaction.reply({ embeds: [data.embed], components: [data.row] });
const collectorFilter = i => i.user.id === interaction.user.id;
try {
const confirmation = await response.awaitMessageComponent({ filter: collectorFilter, time: 60_000 });
console.log("confirmation=", confirmation.customId)
if (confirmation.customId == 'ban') {

await interaction.followUp({ content: 'Please enter your reason:', ephemeral: true });

const filter = m => m.author.id === interaction.user.id; // Collect messages only from the user who interacted
const collector = interaction.channel.createMessageCollector({ filter, max: 1, time: 60000 }); // Adjust time as needed
collector.on('collect', m => {
console.log(`Collected message: ${m.content}`);
// Process the response
// For example, implementing your ban logic here
});

cloud.editData(message, "Bans", 1)
console.log(interaction, "person")
const channel = interaction.client.channels.cache.get(gameInfo.test.log_channel);
const logmsg = `${interaction.user.username} banned user ${message}`
channel.send(logmsg)
await confirmation.update({ content: `${message} has been banned for reason`, components: [] });
} else if (confirmation.customId === 'cancel') {
await confirmation.update({ content: 'Action cancelled', components: [] });
}
} catch (e) {
console.error(e)
await interaction.editReply({ content: 'Confirmation not received within 1 minute, cancelling', components: [] });
}

} catch (error) {
console.error(error);
await interaction.reply({ content: 'Failed to find user', ephemeral: true });
}
},
},
most of the structure is from the tutorial page
client.on(Events.InteractionCreate, async interaction => {
if (interaction.isButton()) {
//console.log(interaction)
//commands.buttons[interaction.customId](interaction)
return
}
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
client.on(Events.InteractionCreate, async interaction => {
if (interaction.isButton()) {
//console.log(interaction)
//commands.buttons[interaction.customId](interaction)
return
}
if (!interaction.isChatInputCommand()) return;

const command = interaction.client.commands.get(interaction.commandName);

if (!command) {
console.error(`No command matching ${interaction.commandName} was found.`);
return;
}

try {
await command.execute(interaction);
} catch (error) {
console.error(error);
if (interaction.replied || interaction.deferred) {
await interaction.followUp({ content: 'There was an error while executing this command!', ephemeral: true });
} else {
await interaction.reply({ content: 'There was an error while executing this command!', ephemeral: true });
}
}
});
what would a modal look like in this context? also want to avoid it being a ban command bc it’s mainly so i can manage my games on mobile if it’s the drop down i do like that, but i want moderators to be able to attach links to the ban messages
d.js docs
d.js docs3mo ago
:guide: Other Interactions: Modals read more
connor
connor3mo ago
yeah one slash command is easy enough, button also easy to click as well as just tying in anything, the input is what i don’t really like on mobile, but also want to verify it’s the right person before banning it’s mainly for cheaters, so game related info will be displayed with the ban option wait modals is perfect i thought they were drop downs i’ll look into this rn reason i don’t want ban slash commands, i need to review the profile prior to ban, and it won’t just be ban but other actions, based on their ingame performance outside of discord test game im implementing has like 1m monthly users but i want to do on much bigger projects w a lot of moderators and a lot of different actions basically cant have the action decided prior to profile lookup one last thing, can i get the modal input the same as the button or will this require resetting up the whole thing
connor
connor3mo ago
No description
d.js docs
d.js docs3mo ago
:method: ButtonInteraction#awaitModalSubmit() Collects a single modal submit interaction that passes the filter. The Promise will reject if the time expires.
connor
connor3mo ago
well the issue happens when displaying the modal, because its still in the original slash command context, so it says the interaction has already been sent or deffered