Refresh autocomplete options with that's dependent on the other parameter

I have a slash command with two parameters, first is the user and the second parameter is an autocomplete that is based on the selected user. But if I selected the wrong user and go back and change to a different user, the second parameter doesn't get updated? Is there a way to fix this without having the user to delete everything and restart? e.g. if I pick user1, second parameter should have options [1, 2, 3] if I pick user2, second paramenter should have options [4, 5, 6] If I pick user1, and move on to second parameter, it shows 1, 2, 3; but if I go back to the first parameter and update that to user2, the second parameter does not get refreshed and still show [4, 5, 6].
5 Replies
d.js toolkit
d.js toolkit14mo 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! - Marked as resolved by staff
alan
alanOP14mo ago
discord.js version - 14.12.1 node -v - 19.6.0
if (interaction.commandName === 'preset') {
// const selectedUser = interaction.options.get('user').value ? interaction.options.get('user').value : interaction.user.id;
//var selectedUser = '162955183670820864';
try {
selectedUser = interaction.options.get('user').value;
} catch {
selectedUser = interaction.user.id;
}
var preset = await sequelize.query(`SELECT \`id\`, \`name\` FROM \`Presets\` WHERE userID = ?`, { replacements: [selectedUser], type: QueryTypes.SELECT });
const focusedValue = interaction.options.getFocused();
const filtered = preset.filter(choice => choice.name.includes(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice.name, value: choice.id })),
).catch(console.err);
}
if (interaction.commandName === 'preset') {
// const selectedUser = interaction.options.get('user').value ? interaction.options.get('user').value : interaction.user.id;
//var selectedUser = '162955183670820864';
try {
selectedUser = interaction.options.get('user').value;
} catch {
selectedUser = interaction.user.id;
}
var preset = await sequelize.query(`SELECT \`id\`, \`name\` FROM \`Presets\` WHERE userID = ?`, { replacements: [selectedUser], type: QueryTypes.SELECT });
const focusedValue = interaction.options.getFocused();
const filtered = preset.filter(choice => choice.name.includes(focusedValue));
await interaction.respond(
filtered.map(choice => ({ name: choice.name, value: choice.id })),
).catch(console.err);
}
Syjalo
Syjalo14mo ago
No, that's how Discord's autocomplete options caching works.
deminearchiver
deminearchiver14mo ago
you could make both options autocomplete and store their values in temp variables
Syjalo
Syjalo14mo ago
That won't fix the issue. Discord Client will still cache choices per option.
Want results from more Discord servers?
Add your server