So basically I've been working on this one bot for my server, I want it to DM the users that join the server, Like whenever a user joins my server, they would receive a DM by my bot? I have used this code now, but it doesn't seem to work, can anyone help?
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Bot is ready!');
bot.on("guildMemberAdd", member => {
member.send("Welcome to the server!")
.catch(console.error);
});});
client.login('<token>');
you are using wrong way it is client
not bot
. Cause you are initial your bot as client
since const client = new Discord.Client()
;. And there is no need to wrap it in ready
event
const Discord = require('discord.js');
const client = new Discord.Client();
client.once('ready', () => {
console.log('Bot is ready!');
});
client.on("guildMemberAdd", member => {
console.log("new member join")
member.send("Welcome to the server!").catch(console.error);
});
client.login('<token>');