Give User Roles with SelectMenu

How can I give the mentioned user the roles selected in the SelectMenu?
19 Replies
Unknown User
Unknown User16mo ago
Message Not Public
Sign In & Join Server To View
Squid
Squid16mo ago
Is that not what you're doing here?
EndergamerMC
EndergamerMC16mo ago
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
Squid
Squid16mo ago
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 are
EndergamerMC
EndergamerMC16mo ago
By interaction in the upper i get the channel of the interaction and the lower one I take the interaction for the function
Squid
Squid16mo ago
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 run
EndergamerMC
EndergamerMC15mo ago
Oh okay but how can I now give them the roles selected after they get mentioned?
Squid
Squid15mo ago
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 work
EndergamerMC
EndergamerMC15mo ago
Like this it doesn't work
Squid
Squid15mo ago
Your first collector is collecting messages, not menu interactions. You can't create variables out of thin air
EndergamerMC
EndergamerMC15mo ago
But how am I able to add the roles that were selected?
Squid
Squid15mo ago
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
EndergamerMC
EndergamerMC15mo ago
So it should work like this?
Squid
Squid15mo ago
Try it and see
EndergamerMC
EndergamerMC15mo ago
I console logged the values of the interaction and I get undefined, why is that?
Squid
Squid15mo ago
You're still redefining the menuInteraction as the second parameter of your messageCollector's collect event, which doesn't exist
EndergamerMC
EndergamerMC15mo ago
Squid
Squid15mo ago
interaction 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 property
EndergamerMC
EndergamerMC15mo ago
Ohh true, didn't think about that.. Thank you! Works now.