select menu
My interaction handler isnt working, giving the roles works but when I click the remove roles option to well obviously remove the roles it just says there was an error updating my roles and sends this into the console:
DiscordAPIError[50035]: Invalid Form Body
role_id[NUMBER_TYPE_COERCE]: Value "all" is not snowflake.
at handleErrors (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async GuildMemberRoleManager.add (C:\Users\alexe\AGU Bot\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:131:7)
at async Client.<anonymous> (C:\Users\alexe\AGU Bot\src\roles.js:558:21) {
requestBody: { files: undefined, json: undefined },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { role_id: [Object] }
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/guilds/1256302762157932655/members/1016447282176077925/roles/all'
}
DiscordAPIError[50035]: Invalid Form Body
role_id[NUMBER_TYPE_COERCE]: Value "all" is not snowflake.
at handleErrors (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:727:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async SequentialHandler.runRequest (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:1128:23)
at async SequentialHandler.queueRequest (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:959:14)
at async _REST.request (C:\Users\alexe\AGU Bot\node_modules\@discordjs\rest\dist\index.js:1272:22)
at async GuildMemberRoleManager.add (C:\Users\alexe\AGU Bot\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:131:7)
at async Client.<anonymous> (C:\Users\alexe\AGU Bot\src\roles.js:558:21) {
requestBody: { files: undefined, json: undefined },
rawError: {
message: 'Invalid Form Body',
code: 50035,
errors: { role_id: [Object] }
},
code: 50035,
status: 400,
method: 'PUT',
url: 'https://discord.com/api/v10/guilds/1256302762157932655/members/1016447282176077925/roles/all'
}
4 Replies
- 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!heres my handler:
two parts since I hit max
// Interaction handler
client.on('interactionCreate', async (interaction) => {
if (!interaction.isStringSelectMenu()) return;
await interaction.deferReply({ ephemeral: true }); // Defer the interaction to prevent timeout
const member = await interaction.guild.members.fetch(interaction.user.id);
const selectedValues = interaction.values;
let categoryRoleIds = [];
switch (interaction.customId) {
case 'pronouns':
categoryRoleIds = ['1256314021221761065', '1256313952720257176', '1256314088116719707', '1256314120467255306'];
break;
case 'sexuality':
categoryRoleIds = ['1256314313623343198', '1256314391867949258', '1256314450173235230'];
break;
case 'continent':
categoryRoleIds = ['1256314957033766973', '1256314999723397200', '1256315100650799184', '1256314912448315434', '1256315138097676340', '1256314749637886093', '1256315061547569274'];
break;
case 'zodiac':
categoryRoleIds = ['1256315831575384256', '1256315877310206062', '1256315915709055047', '1256315953038364792', '1256315980989202457', '1256316013234880553', '1256316050379771965', '1256316085607731271', '1256316142373572688', '1256316196970696765', '1256316252918513724', '1256316326566297674'];
break;
case 'dm_status':
categoryRoleIds = ['1256315493154033745', '1256315595507503154', '1256315435222306876'];
break;
case 'age_range':
categoryRoleIds = ['1256314534004658269', '1256314633149743164'];
break;
}
// Interaction handler
client.on('interactionCreate', async (interaction) => {
if (!interaction.isStringSelectMenu()) return;
await interaction.deferReply({ ephemeral: true }); // Defer the interaction to prevent timeout
const member = await interaction.guild.members.fetch(interaction.user.id);
const selectedValues = interaction.values;
let categoryRoleIds = [];
switch (interaction.customId) {
case 'pronouns':
categoryRoleIds = ['1256314021221761065', '1256313952720257176', '1256314088116719707', '1256314120467255306'];
break;
case 'sexuality':
categoryRoleIds = ['1256314313623343198', '1256314391867949258', '1256314450173235230'];
break;
case 'continent':
categoryRoleIds = ['1256314957033766973', '1256314999723397200', '1256315100650799184', '1256314912448315434', '1256315138097676340', '1256314749637886093', '1256315061547569274'];
break;
case 'zodiac':
categoryRoleIds = ['1256315831575384256', '1256315877310206062', '1256315915709055047', '1256315953038364792', '1256315980989202457', '1256316013234880553', '1256316050379771965', '1256316085607731271', '1256316142373572688', '1256316196970696765', '1256316252918513724', '1256316326566297674'];
break;
case 'dm_status':
categoryRoleIds = ['1256315493154033745', '1256315595507503154', '1256315435222306876'];
break;
case 'age_range':
categoryRoleIds = ['1256314534004658269', '1256314633149743164'];
break;
}
try {
// Handle remove-all
if (selectedValues.includes('remove-all')) {
// Filter out roles that the member already has in this category
const rolesToRemove = categoryRoleIds.filter(roleId => member.roles.cache.has(roleId));
if (rolesToRemove.length > 0) {
await member.roles.remove(rolesToRemove);
await interaction.editReply({ content: 'All roles in this category have been removed.' });
} else {
await interaction.editReply({ content: 'You do not have any roles from this category.' });
}
} else {
// Process each selected value
for (const selectedValue of selectedValues) {
// Ensure we're working with a valid role ID
const selectedRoleId = selectedValue.split('-')[1];
if (selectedRoleId) {
// Filter out the current role from the category before removing the others
const previousRoleIds = categoryRoleIds.filter(id => id !== selectedRoleId);
const rolesToRemove = previousRoleIds.filter(roleId => member.roles.cache.has(roleId));
if (rolesToRemove.length > 0) {
await member.roles.remove(rolesToRemove);
}
await member.roles.add(selectedRoleId);
}
}
await interaction.editReply({ content: 'Your selected roles have been updated!' });
}
} catch (error) {
console.error(error);
await interaction.editReply({ content: 'There was an error updating your roles.' });
}
});
try {
// Handle remove-all
if (selectedValues.includes('remove-all')) {
// Filter out roles that the member already has in this category
const rolesToRemove = categoryRoleIds.filter(roleId => member.roles.cache.has(roleId));
if (rolesToRemove.length > 0) {
await member.roles.remove(rolesToRemove);
await interaction.editReply({ content: 'All roles in this category have been removed.' });
} else {
await interaction.editReply({ content: 'You do not have any roles from this category.' });
}
} else {
// Process each selected value
for (const selectedValue of selectedValues) {
// Ensure we're working with a valid role ID
const selectedRoleId = selectedValue.split('-')[1];
if (selectedRoleId) {
// Filter out the current role from the category before removing the others
const previousRoleIds = categoryRoleIds.filter(id => id !== selectedRoleId);
const rolesToRemove = previousRoleIds.filter(roleId => member.roles.cache.has(roleId));
if (rolesToRemove.length > 0) {
await member.roles.remove(rolesToRemove);
}
await member.roles.add(selectedRoleId);
}
}
await interaction.editReply({ content: 'Your selected roles have been updated!' });
}
} catch (error) {
console.error(error);
await interaction.editReply({ content: 'There was an error updating your roles.' });
}
});
Unknown User•4w ago
Message Not Public
Sign In & Join Server To View
:typealias: RoleResolvable
@14.16.3
Data that can be resolved to a Role object. This can be:* A Role* A Snowflake