I've been trying to find a way to DM a member a welcome message when they join the server. I have a way to DM the member, but I can't find a way to trigger it when someone joins. here's the code that will DM the member a message:
message.author.send('message content here')
Here's the code that doesn't seem to work:
bot.on("guildMemberAdd", member => {
log("new member joined the server")
member.send("Welcome to the server!");
});
Note: I have a function called log, this is not what's causing the issue (i think), it's declared before this
Thanks for any help :)
CodePudding user response:
Your code isn't working, most likely, because you haven't requested the GUILD_MEMBERS
intent which is necessary for the guildMemberAdd
event.
Here is a simple example on how to request the GUILD_MEMBERS
intent.
const { Client, Intents } = require("discord.js");
const bot = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MEMBERS],
});
Make sure you have also enabled it in your bot's settings. (Bot -> Privileged Gateway Intents -> SERVER MEMBERS INTENT)