B
B
badlycoder2020-11-20 18:17:46
Node.js
badlycoder, 2020-11-20 18:17:46

Role assignment not working, what's the problem?

When a person enters the discord server, he is not given a role, but everything seems to be written correctly.

const Discord = require('discord.js');
const bot = new Discord.Client();

bot.on('guildMemberAdd', (member) => {
    let role = member.guild.roles.find('name', "Candidat");
    member.addRole(role);
});

bot.login('*******')

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2020-11-20
@badlycoder

in Discord Developer Portal , select your app, go to Bot tab => Privileged Gateway Intents => enable Presence Intent and Server Members Intent.

Z
ZephyrCode, 2020-11-20
@ZephyrCode

In DiscordJs v12, the way roles are assigned has changed.
member.roles.add(role)
I advise you to use the official guide and use only relevant video tutorials

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question