I was coding a Discord bot, and everything was fine. However, when I update discord.js from 13.8.0 to 13.8.1 and try to give members role by clicking button and submit a modal, it shows this error:
/app/node_modules/discord.js/src/rest/RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Access
at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async GuildMemberRoleManager.add (/app/node_modules/discord.js/src/managers/GuildMemberRoleManager.js:124:7)
at async /app/events/guild/modalSubmit.js:10:7 {
method: 'put',
path: '/guilds/926089413933539359/members/606668363531288577/roles/926252511201988678',
code: 50001,
httpStatus: 403,
requestData: { json: undefined, files: [] }
}
I've checked the permissions of the bot, but it already had all permissions.
Code of the modalSubit:
const response = modal.getTextInputValue('verification-input');
if(response.toLowerCase()!=="lock"){
await modal.reply({content:"Failed!",ephemeral: true});
return;
}
modal.guild.roles.fetch('926252511201988678')
.then(async role=>{
await modal.member.roles.add(role);
})
await modal.reply({content:"Finished!",ephemeral: true});
}
You gotta make sure your bot's highest role is above the role you're trying to add in the guild hierarchy
Well, I think I figure it out. The bot joined a 2FA server, without a 2FA account creating it. I found this out by clicking another button which shows an error like this:
/rbd/pnpm-volume/d50c9aa3-e1b3-4f3c-a369-a5ec640ad85c/node_modules/discord.js/src/rest/RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Two factor is required for this operation
at RequestHandler.execute (/rbd/pnpm-volume/d50c9aa3-e1b3-4f3c-a369-a5ec640ad85c/node_modules/discord.js/src/rest/RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (/rbd/pnpm-volume/d50c9aa3-e1b3-4f3c-a369-a5ec640ad85c/node_modules/discord.js/src/rest/RequestHandler.js:51:14)
at async GuildChannelManager.create (/rbd/pnpm-volume/d50c9aa3-e1b3-4f3c-a369-a5ec640ad85c/node_modules/discord.js/src/managers/GuildChannelManager.js:157:18)