Error 50013 thrown when giving and removing roles

Heyy so I'm getting started with discord.js and created a command that should give and remove a role depending on whether a user has it via interactions. I think I understand how roles work in discord, but I'm confused as to why I'm getting a permission error. Hopefully someone can help!
17 Replies
d.js toolkit
d.js toolkit16mo 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!
Spur
SpurOP16mo ago
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('red')
.setDescription('Gives the red role'),
async execute(interaction) {
try {
const roleID = "1127757615112392704";
if (interaction.guild.roles.cache.get(roleID) != null) {
if (interaction.member.roles.cache.get(roleID) != null) {
await interaction.member.roles.remove(roleID);
await interaction.reply(`Role is already present and has been removed`);
} else {
await interaction.member.roles.add(roleID);
await interaction.reply('Role has been added!');
}
} else {
await interaction.reply({content: `hmm I couldn't find that role listed for this server`, ephemeral: true});
}
} catch(error) {
await interaction.reply({content: `Something went wrong: ${error.message}`, ephemeral: true});
}
},
};
const { SlashCommandBuilder } = require('discord.js');

module.exports = {
data: new SlashCommandBuilder()
.setName('red')
.setDescription('Gives the red role'),
async execute(interaction) {
try {
const roleID = "1127757615112392704";
if (interaction.guild.roles.cache.get(roleID) != null) {
if (interaction.member.roles.cache.get(roleID) != null) {
await interaction.member.roles.remove(roleID);
await interaction.reply(`Role is already present and has been removed`);
} else {
await interaction.member.roles.add(roleID);
await interaction.reply('Role has been added!');
}
} else {
await interaction.reply({content: `hmm I couldn't find that role listed for this server`, ephemeral: true});
}
} catch(error) {
await interaction.reply({content: `Something went wrong: ${error.message}`, ephemeral: true});
}
},
};
Gateway intent bits:
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMessages,
],
});
Error is thrown right after line 12 (await interaction.member.roles.remove(roleID);) runs which leads me to think that it is a role-management permission problem
treble/luna
treble/luna16mo ago
does your bot have permissions to manage roles and is the bot's highest role above that role?
Spur
SpurOP16mo ago
When I added it to the test server, I set its permission code as 8 which I thought just made it an admin. I'll send its explicit perms rq
treble/luna
treble/luna16mo ago
administrator does not mean it can add any role
Spur
SpurOP16mo ago
treble/luna
treble/luna16mo ago
its still limited to the hierarchy
Spur
SpurOP16mo ago
Ah oof
treble/luna
treble/luna16mo ago
it can add roles that are below its highest role any roles above that, or managed roles, will throw a missing perms error
Spur
SpurOP16mo ago
I see. Will enabling every permission allow it to give any role?
treble/luna
treble/luna16mo ago
no
Spur
SpurOP16mo ago
The role it is trying to give is simply a color role with no perms attatched btw
treble/luna
treble/luna16mo ago
administrator is all perms
Spur
SpurOP16mo ago
Ah ok
treble/luna
treble/luna16mo ago
but in order to give the role, the bot's role needs to be higher by default, new roles, and i assume this includes the bot role, are placed at the bottom you also cannot moderate members that have a higher role
Spur
SpurOP16mo ago
You were right! Adjusting that order fixed it completely I had no idea that the order in which roles are stacked mattered lol Thank you!
treble/luna
treble/luna16mo ago
yw!
Want results from more Discord servers?
Add your server