roles not being added

else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
39 Replies
d.js toolkit
d.js toolkit13mo 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! - Marked as resolved by OP
treble/luna
treble/luna13mo ago
roles.delete is not how you remove a role you're just mutating the cache which you shouldnt
SuperPEKKA336
SuperPEKKA336OP13mo ago
yes oh what do you suggest?
treble/luna
treble/luna13mo ago
use the set method like you do now but clone the collection instead of mutating
SuperPEKKA336
SuperPEKKA336OP13mo ago
k one sec
else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache.clone;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache.clone;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
like that? also what would i use to add the value array to roles? .add isnt a function
treble/luna
treble/luna13mo ago
clone is a function and i'm not sure what that for loop is supposed to do because <Collection>.add is not a function nor would it be valid since that doesnt look like a snowflake
SuperPEKKA336
SuperPEKKA336OP13mo ago
the values are what the users selected tehy are in camel case
treble/luna
treble/luna13mo ago
okay
SuperPEKKA336
SuperPEKKA336OP13mo ago
and i turn em upper case to match the roleIDs in my json file
treble/luna
treble/luna13mo ago
thats what i meant .
SuperPEKKA336
SuperPEKKA336OP13mo ago
yeah what is the name of the function?
treble/luna
treble/luna13mo ago
<Collection>.set mapped by snowflake and role object
SuperPEKKA336
SuperPEKKA336OP13mo ago
well i want to add certain roles
treble/luna
treble/luna13mo ago
or just an array of snowflakes, probably easier you need the id not the name
SuperPEKKA336
SuperPEKKA336OP13mo ago
so
treble/luna
treble/luna13mo ago
you are using the name
SuperPEKKA336
SuperPEKKA336OP13mo ago
where?
treble/luna
treble/luna13mo ago
hold on
SuperPEKKA336
SuperPEKKA336OP13mo ago
k
treble/luna
treble/luna13mo ago
you're calling toUpperCase...on a Role? ah no still what i saod
SuperPEKKA336
SuperPEKKA336OP13mo ago
im stupid
SuperPEKKA336
SuperPEKKA336OP13mo ago
else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache.clone;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = ROLE_IDS.value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
else if(interaction.isStringSelectMenu()) // String Select Menu Interactions
{
let roles = interaction.member.roles.cache.clone;
const value = interaction.values;
const COUNTERSTRIKE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_COUNTERSTRIKE);
const FORTNITE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_FORTNITE);
const LEAGUEOFLEGENDS = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_LEAGUEOFLEGENDS);
const MINECRAFT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_MINECRAFT);
const OVERWATCH = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_OVERWATCH);
const RAINBOWSIX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_RAINBOWSIX);
const ROBLOX = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROBLOX);
const ROCKETLEAGUE = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_ROCKETLEAGUE);
const VALORANT = interaction.guild.roles.cache.get(ROLE_IDS.GAMES_VALORANT);

roles.delete(COUNTERSTRIKE.ID);
roles.delete(FORTNITE.ID);
roles.delete(LEAGUEOFLEGENDS.ID);
roles.delete(MINECRAFT.ID);
roles.delete(OVERWATCH.ID);
roles.delete(RAINBOWSIX.ID);
roles.delete(ROBLOX.ID);
roles.delete(ROCKETLEAGUE.ID);
roles.delete(VALORANT.ID);

for(let i; i < value.length; i++)
{
value[i] = ROLE_IDS.value[i].toUpperCase();
}

roles.add(value);

interaction.member.roles.set(roles);
}
like that? but if .add doesnt exist, how would i add the roles that the user selected to the roles they already have? basically what im trying to do is when a user uses the select menu any roles that they already have from the select menu (counterstrike, fortnite, etc.) are removed then it would add the roles they selected
treble/luna
treble/luna13mo ago
this part
No description
treble/luna
treble/luna13mo ago
is entirely invalid because you 1) have to use snowflakes, and 2 add is not a function you either have to pass in a Collection keyed by snowflake and role, or an array of role id's in your case the second would be the best
SuperPEKKA336
SuperPEKKA336OP13mo ago
No description
SuperPEKKA336
SuperPEKKA336OP13mo ago
thats what im trying to do
treble/luna
treble/luna13mo ago
just map the cache to an array, iterate over it and remove the roles you want
SuperPEKKA336
SuperPEKKA336OP13mo ago
ROLE_IDS.value[i].toUpperCase(); the value of a selection is games_gameName the name of the role id is GAMES_GAMENAME so i get the ID and store it in the array
treble/luna
treble/luna13mo ago
no you're storing the name of the role regardless that part of your code is just redundant do this
SuperPEKKA336
SuperPEKKA336OP13mo ago
ok how would i map the cache to an array?
treble/luna
treble/luna13mo ago
.map(r => r.id) and then you would have to remove the ids you want to remove which is just basic array stuff
SuperPEKKA336
SuperPEKKA336OP13mo ago
yeah whats r
treble/luna
treble/luna13mo ago
a Role
SuperPEKKA336
SuperPEKKA336OP13mo ago
so roles.(game => game.id);
treble/luna
treble/luna13mo ago
map on the cache
SuperPEKKA336
SuperPEKKA336OP13mo ago
roles is the cache cache.map
treble/luna
treble/luna13mo ago
yes
SuperPEKKA336
SuperPEKKA336OP13mo ago
ok thanks
Want results from more Discord servers?
Add your server