Give User Roles with SelectMenu

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