onInteractionCreate doesn't get called when I select a previously deselected parameter

I have a command that has 2 autocomplete parameters:
const data = new SlashCommandBuilder()
.setName(name)
.setDescription("Sets the current channel as a daily sync channel")
.addStringOption((option) =>
option
.setName(Options.org)
.setDescription("Filter for organization")
.setRequired(true)
.setAutocomplete(true)
)
.addStringOption((option) =>
option
.setName(Options.team)
.setDescription("Filter for team")
.setRequired(false)
.setAutocomplete(true)
);
const data = new SlashCommandBuilder()
.setName(name)
.setDescription("Sets the current channel as a daily sync channel")
.addStringOption((option) =>
option
.setName(Options.org)
.setDescription("Filter for organization")
.setRequired(true)
.setAutocomplete(true)
)
.addStringOption((option) =>
option
.setName(Options.team)
.setDescription("Filter for team")
.setRequired(false)
.setAutocomplete(true)
);
By default it pops up the org as an option which works fine, but if I press backspace and delete this suggestion I can select other parameters. In my case I selected team, and proceeded to select a team. After that when I select org from the parameters I get displayed the previous suggestions. My problem is that I have some code that filters organizations if a team is selected:
if (focusedOption.name === OrgAndTeamOptions.org) {
// 📘 if we have a team, then only the team's org is selectable
if (teamId) {
const teamOrgId = user.teams.find(
(team) => team.teamId === teamId
)?.team.orgId;
choices = user.organizations
.filter((org) => org.orgId === teamOrgId)
.map((org) => ({
name: org.organization.name,
value: org.orgId,
}));
} else {
choices = user.organizations.map((org) => ({
name: org.organization.name,
value: org.orgId,
}));
}
}
if (focusedOption.name === OrgAndTeamOptions.org) {
// 📘 if we have a team, then only the team's org is selectable
if (teamId) {
const teamOrgId = user.teams.find(
(team) => team.teamId === teamId
)?.team.orgId;
choices = user.organizations
.filter((org) => org.orgId === teamOrgId)
.map((org) => ({
name: org.organization.name,
value: org.orgId,
}));
} else {
choices = user.organizations.map((org) => ({
name: org.organization.name,
value: org.orgId,
}));
}
}
This works if the user starts to type something, but the whole InteractionCreate callback doesn't get called when I simply select org, the old list is displayed instead. How can I force the reloading of the organizations that the user can pick? I'd like to use autocomplete as it is possible that there are many organizations / teams to choose from.
5 Replies
d.js toolkit
d.js toolkit16mo 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!
addamsson
addamssonOP16mo ago
Looks like this
addamsson
addamssonOP16mo ago
No description
addamsson
addamssonOP16mo ago
is this the expected behavior? Or is there a best practice that I can employ here if the possible values in my fields depend on values selected in other fields?
Syjalo
Syjalo16mo ago
That's how Discord's client caching works. Not related to discord.js. You can vote for this feedback btw
Want results from more Discord servers?
Add your server