Give User Roles with SelectMenu
How can I give the mentioned user the roles selected in the SelectMenu?
19 Replies
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
Is that not what you're doing here?
Yes but how can I get the values of the SelectMenu into the code block of the mention collector to add the role there?
Like this it doesn’t work, it says something like this is not an array or snowflake
I don't really understand the flow of your code
For starters, you have (at least) 2 variables named
interaction
: one you defined outside of this screenshot, and another that you collect via your component collector
You should name them two different things so you don't confuse yourself on what they areBy interaction in the upper i get the channel of the interaction and the lower one I take the interaction for the function
You should distinguish those two using their names
For instance, you could call the interaction that initiates the command
commandInteraction
and the one from the select menu menuInteraction
The actual names don't matter, but it'll help you in the long runOh okay but how can I now give them the roles selected after they get mentioned?
Your select menu interaction has a
values
property which is an array of the values they selected
If those are role ids, something similar to your original code (but now with the correct interaction) should workLike this it doesn't work
Your first collector is collecting messages, not menu interactions. You can't create variables out of thin air
But how am I able to add the roles that were selected?
What if you create the component collector within the collect event of the message collector?
If one relies on the other, you shouldn't keep them separate
You can't collect the menu interaction of which roles to get until you collect the message interaction of who's getting those roles
So it should work like this?
Try it and see
I console logged the values of the interaction and I get undefined, why is that?
You're still redefining the menuInteraction as the second parameter of your messageCollector's
collect
event, which doesn't existinteraction
is the ChatInputCommandInteraction that started your command
menuInteraction
is the interaction generated by the user using the select menu
The command interaction does not have a .values
propertyOhh true, didn't think about that.. Thank you! Works now.