简体   繁体   中英

discord.js 'guildMemberAdd' Event not working despite turning on Intents

This is my first question here, so I apologize in advance if I'm doing something wrong.

As you may know, Discord recently implemented some changes which made it necessary to activate Privileged Gateway Intents so that bots can keep welcoming new members and giving them roles.

My bot is in a single server, so I granted it both PRESENCE INTENT and SERVER MEMBERS INTENT. I was under the impression that this should be enough to get the bot to start working as normal again, but sadly it still doesn't welcome new members nor does it give it their custom role. Everything else works as normal though (it responds to !nameofthebot), and the bot is online. I also manually gave it all necessary permissions in the channels where I want them to be active.

I'm not very knowledgeable in code and I built this bot thanks to reading discussion here and on other sites. As such, I'm wondering if maybe there's something that needs an update on this level, too. Here's the code in question:

 require('dotenv').config() const Discord = require('discord.js'); const client = new Discord.Client(); client.on('ready', () => { console.log(`Logged in as ${client.user.tag}!`); }); client.on('guildMemberAdd', function(member) { member.guild.channels.get("539191415624826903").send(`Welcome to our server <@${member.user.id}>. Please do not forget to read the rules, and if you have time, don't hesitate to tell us a little about yourself.<:__:551298213622317066>`) var role = member.guild.roles.get("549670094079524867"); member.addRole(role) }); client.login(process.env.BOT_TOKEN);

I double-checked the channel and member IDs and they should be fine. Just in case this can be of help, the code is hosted on GitHub and the bot runs thanks to Heroku.

Thank you in advance to anyone who may be able to help me figure out what I'm missing.

For guildMemberAdd, guildMemberRemove, guildMemberUpdate events you need to enable "GUILD_MEMBERS" intent

Please check this link

this is how I am creating my bot client:

const Discord = require("discord.js");  
const { Client, Intents } = require("discord.js");

client = new BotClient({
  ws: { intents: [Intents.NON_PRIVILEGED, "GUILD_MEMBERS"] },
});

OR

const Discord = require("discord.js");  
const { Client, Intents } = require("discord.js");

client = new BotClient({
  ws: { intents: Intents.ALL },
});

Please also make sure you have enabled PRIVILEGED Intents on your Discord Developer Portal

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM