I've watched numerous videos, and followed examples online, and still can't get my discord bot to simply send a message upon a member joining. Maybe I'm missing out on an important update?
//require the necessary discord.js classes
const { Client, Intents } = require("discord.js");
const { token } = require("./config.json");
//create a new client instance
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
//when the client is ready, run this code (only once)
client.on('ready', () => {
console.log("Online");
});
//sends user a welcome message upon joining
client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.get('921490782958014576');
channel.send("Welcome to the server!!")
});
client.login(token);
I get nothing. Nada. I've tried several different pieces of code. I've TRIPLE checked the permissions. This is very frustrating. I've tried unadding and readding the bot to the server. I checked up on the discord.js documentation and nothing seems to be wrong with my code. To me it seems as if the guildMemberAdd isn't emitting anything. I'm using notepad++ to edit my code. I feel I could be using something better for debugging purposes possibly.
The issue may be due to missing intents. Try adding the GUILD_MEMBERS
intent to your list of intents like so.
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS] });
discord.js docs: https://discord.js.org/#/docs/main/stable/class/Intents?scrollTo=s-FLAGS
Developer docs: https://discord.com/developers/docs/topics/gateway#gateway-intents