'How to make my bot add roles to members according to one of the two roles chosen by them in Discord?
The details of my problem is as follows when I do the verification I get this:
C:\Users\kakaroto\Desktop\mybot\node_modules\discord.js\src\rest\RequestHandler.js:350
throw new DiscordAPIError(data, res.status, request);
^
DiscordAPIError: Missing Permissions
at RequestHandler.execute (C:\Users\kakaroto\Desktop\mybot\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async RequestHandler.push (C:\Users\kakaroto\Desktop\mybot\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
at async GuildMemberRoleManager.add (C:\Users\kakaroto\Desktop\mybot\node_modules\discord.js\src\managers\GuildMemberRoleManager.js:124:7) {
method: 'put',
path: '/guilds/957295483452264468/members/942795003346960464/roles/957303388150857758',
code: 50013,
httpStatus: 403,
requestData: { json: undefined, files: [] }
}
Node.js v17.8.0
This is all I did in visual studio Code, in javascript to add this function to my bot on my Discord server:
const { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] }); 'Intents'
client.on('ready', () => {
console.log(`Bot ready! ${client.user.tag}`);
});
client.once("messageCreate", message => {
if(message.channel.id === "numberID"){
if(message.author.bot) return;
if(message.content === 'I agree to be an Apprentice'){
message.member.roles.add("numberID");
message.author.send("Thank you for verifying.");
message.delete();
}
if(message.content === 'I agree to be a Spectator'){
message.member.roles.add("numberID");
message.author.send("Thank you for verifying.");
message.delete();
}
else{
message.author.send("Having problems? Talk to an admin.");
message.delete();
}
}
});
client.login('numbertoken');
What I am trying to do is that in the verification channel users without roles can write one of the two options which the bot will assign them the role and send them a private message saying thanks for verifying you.
I hope you can help me please, I tried everything, but I still don't understand very well if I need to add another intents or enable something, I'm waiting for your answer, thank you very much! y version of discord according to this code: npm list discord.js is [email protected]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
