The fast way: use the template
- Create a bot from the Welcome template and choose Node.js (discord.js).
- Open Test, press Simulate member join, and watch the welcome message and role assignment.
- Add
DISCORD_TOKEN, enable the Server Members Intent, and deploy.
How it works in code
Under the hood, a welcome bot listens to the GuildMemberAdd event. That event needs the privileged Server Members Intent.
const { Client, GatewayIntentBits, Events } = require("discord.js");
const client = new Client({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
});
client.on(Events.GuildMemberAdd, async (member) => {
const channel = member.guild.channels.cache.find((c) => c.name === "welcome");
if (channel?.isTextBased()) {
await channel.send(`Welcome to ${member.guild.name}, ${member}!`);
}
const role = member.guild.roles.cache.find((r) => r.name === "Member");
if (role) await member.roles.add(role);
});
client.login(process.env.DISCORD_TOKEN);Common problems
- Nothing happens on join — the Server Members Intent is off in the Developer Portal.
- Missing Permissions (50013) — the bot lacks Manage Roles, or its role is below
Member. - Unknown channel — create a
#welcomechannel or change the name.
You can rehearse the permission error in the sandbox: enable “Bot role at the bottom of the hierarchy” and simulate a join.
Ready to build your first bot?
Create a bot — free