Users & Role select menu not clearing when it should

I am not sure if this is a bug in discord.js discord it self or me missing something but this seems broken. I seem to be unable to clear the select when the user has interacted with it, it is possible to clear values set by the bot via setDefaultUsers but as soon as the user selects or deselects something and triggers interactionCreate it becomes impossible to clear it. I made some code that is able to reproduce this with the following steps * Enter the token into the TOKEN const * Start the bot using node * In any channel which the bot can see and send messages in send .test * Select a few users * Send .test again * Press the reset button (the menu should be cleared) * Select a few users again * Press the reset button again (No users will be cleared this time even though the same code is being executed) https://gist.github.com/Jarco-dev/5c6235688ca6cee26bb5a85535c9a1a2
Gist
Replication code for bug
Replication code for bug. GitHub Gist: instantly share code, notes, and snippets.
40 Replies
d.js toolkit
d.js toolkit•5mo 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!
Jarco
Jarco•5mo ago
I am using discord.js 14.14.1 and node.js v18.12.1
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
as in creating new menu's from it?
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
Okay i am really really confused, both situation below where recorded right after each other with no change in code or even a bot restart in between the interactionCreate event code used:
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
resetBtn.components[0].setDisabled(true);
selectedUsers = [];

i.message.components[0].components[0].data.default_values = [];
console.log(i.message.components[0].components[0].data); // has default_values: []
i.update({components: [i.message.components[0], resetBtn]});
}
});
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
resetBtn.components[0].setDisabled(true);
selectedUsers = [];

i.message.components[0].components[0].data.default_values = [];
console.log(i.message.components[0].components[0].data); // has default_values: []
i.update({components: [i.message.components[0], resetBtn]});
}
});
When i start off with a empty menu supplied by the bot it doesn't work at all what ever i do http://i.jarco.dev/eV0umLlC.mp4 But then when i first add some values into the menu and run the command again (so the bot supplies the menu with a few defaults values set) it works perfectly http://i.jarco.dev/n8yARntO.mp4
Jarco
!false is funny because it's true
Jarco
!false is funny because it's true
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
But how do i update the things i want to change about the components before then?
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
Yes and the button needs to get disabled when pressing the button
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
the butting disabling works fine just the menu clearing doesn't but i'll try regardless to try to debug stuff Trying it in the way you said to makes it not reset in anyway anymore, with the code i had previously it would reset but only in that specific situation which I can't narrow down due you have any clue why it could be that way? The code i just tried based on what you said (it's a new button cuz it was giving issues and i figured this achives the same anyway)
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
const button = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);
selectedUsers = [];
i.update({components: [i.message.components[0], button]});
}
});
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
const button = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);
selectedUsers = [];
i.update({components: [i.message.components[0], button]});
}
});
Honestly i am like 80% sure this is some sort of bug in discord.js where it doesn't send the default_values: [] to the api somehow
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
The button works as intended, feel free to try it for your self to replicate
d.js docs
d.js docs•5mo ago
Structures from the API cannot be edited directly. To do so, you can create a new structure (a builder) using the .from() method
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
const newEmbed = EmbedBuilder.from(embed).setTitle("title")
const newRow = ActionRowBuilder.from(row).addComponents(component)
Jarco
Jarco•5mo ago
My issue how ever is not the button it's the menu which i am not disabling just clearing unless it started off with some default values
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
Okay, so in the first video it manages to disable the button (as intended) but it does not clear the menu which it should have done so. But then in the 2nd video when i first select a few things in the menu and then run the command again to get a new menu (which is now populated with default values) the reset button works as intended aka the button gets disabled and the menu gets cleared So somehow you can't clear the menu if it didn't start off with default values how ever you can clear the menu if it was created with some default values already comming from the bot and it also only works in this janky way just creating a entire new menu with the builders means it won't even work in the 2nd situation
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
What i mean is that if the menu started empty and i then select a few values i can't clear those values anymore with the bot
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
No, no errors what so ever infact the button that gets disabled with in the same <Interaction>.update call does actually get disabled
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
This 2nd video is exactly how i want it to function how ever this functionality is aparently not achievable if the menu didn't start off with some <UserSelectMenuBuilder>.setDeafultUsers() set before sending it
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
How so, shouldn't you be able to remove the selected values via the bot? because regardless of what it should or shouldn't be currently you can do either one depending on the situation and that doesn't seem right either 🤔 (also i have a idea of how to demonstrate this more clearly I'll change up some code)
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
I don't think you understand what i mean with no values selected, I mean that if the menu started empty and the user then selects a few values and you after that try to reset the menu you are not able to clear those selected values.
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
I've tried that and that doesn't do anything
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
selectedUsers = [];

const resetBtn = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);

i.update({components: [i.message.components[0], resetBtn]});
}
});
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
selectedUsers = [];

const resetBtn = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);

i.update({components: [i.message.components[0], resetBtn]});
}
});
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
This code gives the same results as in the videos I showed earlier had to create a entire new menu because referencing the old one didn't work probably because i set the default values on that one else where in the code
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
selectedUsers = [];

const resetBtn = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);

const newUsersMenu = new ActionRowBuilder().setComponents(
new UserSelectMenuBuilder()
.setCustomId("usersMenu")
.setPlaceholder("Select the desired user(s)")
.setMinValues(0)
.setMaxValues(25)
);

i.update({components: [newUsersMenu, resetBtn]});
}
});
client.on("interactionCreate", i => {
if (i.isUserSelectMenu() && i.customId === "usersMenu") {
resetBtn.components[0].setDisabled(i.values.length === 0);
selectedUsers = i.values;
i.update({components: [usersMenu, resetBtn]});
} else if (i.isButton() && i.customId === "resetMenu") {
selectedUsers = [];

const resetBtn = new ActionRowBuilder().setComponents(
new ButtonBuilder()
.setCustomId("resetMenu")
.setLabel("Reset menu")
.setStyle(2)
.setDisabled(true)
);

const newUsersMenu = new ActionRowBuilder().setComponents(
new UserSelectMenuBuilder()
.setCustomId("usersMenu")
.setPlaceholder("Select the desired user(s)")
.setMinValues(0)
.setMaxValues(25)
);

i.update({components: [newUsersMenu, resetBtn]});
}
});
I feel like there might be some weird edge case either in discord.js where it doesn't send default_values: [] to the API in this specific occurance or a weird edge case on discord's side because i doubt this is intended as that would be very inconsistand
Unknown User
Unknown User•5mo ago
Message Not Public
Sign In & Join Server To View
Jarco
Jarco•5mo ago
I think i am going to create some code which more clearly demonstrates this and then probably create a issue on discord.js because i feel like people who know how it works internally might know what could be going on
SpecialSauce
SpecialSauce•5mo ago
I don’t think the types line up to just resend the received user menu. Have you tried UserSelectMenuBuilder.from(<component>)?
Jarco
Jarco•5mo ago
don't remember if i specificly tried that but i think so, but even in the last example (the code above here) i just recreated the entire menu from scratch and it still didn't do the job
SpecialSauce
SpecialSauce•5mo ago
Oh I did see where that wasn’t working. Yeah that should do it.
Jarco
Jarco•5mo ago
But yea i think it's some kinda weird edge case thats happening either in discord.js or discord Managed to narrow down the probably bug further but it sure doesn't make any more sense than it did before @SpecialSauce @Jô 🌈🦄Figured out the issue, it's a discord client side bug if you restart discord it fixes is so this is upto discord to fix I have no clue where to check if it's been reported already and if not idk where to report it either