bot can't manage roles on user
THE ERROR:
TypeError: Cannot read properties of undefined (reading 'id')
at get cache [as cache] (C:\Users\2DF2ZDT\Documents\New folder\node_modules\di ers\GuildMemberRoleManager.js:37:101)
at GuildMemberRoleManager.add (C:\Users\2DF2ZDT\Documents\New folder\node_modu
\managers\GuildMemberRoleManager.js:134:31)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
THE CODE:
// Grant the user the "1 character token" role here
// Replace ROLE_ID with the actual ID of the role
const roleId = '1126221526161686679';
const member = await interaction.guild.members.fetch(userId);
member.roles
.add(roleId)
.then(() => {
interaction.reply('Character created. You have been granted the "1 character token" role.');
})
.catch((err) => {
console.error(err);
interaction.reply('Character created. Failed to grant role.');
});
My intents are there in the index.js file. I checked the role ID. It can get the userId and post it to the database but it can't manage the user's roles. I checked the permissions on my bot it has administrator permission so it should be able to do everything. I checked that the bot's heirarchy is above everything else. I was able to console log the user so it seems like it's just a permissions problem related to manage guild member roles but I don't understand because I have the bot on admin privelage. Stumped on this one.
8 Replies
• What's your exact discord.js
npm list discord.js
and node node -v
version?
• Post the full error stack trace, not just the top part!
• Show your code!
• Explain what exactly your issue is.
• Not a discord.js issue? Check out #useful-servers.Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
it's in my index.js
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
const client = new Client({ intents: [GatewayIntentBits.GuildMessages, GatewayIntentBits.GuildMembers] });
Unknown User•2y ago
Message Not Public
Sign In & Join Server To View
k
I found the root of the problem. It can't find the role. Still not sure why that is.
but at least I have something to work off of