Welcome message

I've created a welcome command that i can do /welcome channel and then in that channel everytime someone join the server there should be send a welcome message with an emebed, when someone joins it doens't work, so when i run the command it says: "Welcome messages will now be sent in generale" but then when someone joins he doesn't. welcome.js:
const { SlashCommandBuilder, EmbedBuilder, ChannelType, Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });


let welcomeChannelId;

module.exports = {
data: new SlashCommandBuilder()
.setName('welcome')
.setDescription('Set the welcome channel for new members.')
.addChannelOption(option =>
option.setName('channel')
.setDescription('Channel where welcome messages will be sent')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)),

async execute(interaction) {
const channel = interaction.options.getChannel('channel');

if (!channel) {
return interaction.reply({ content: 'Please provide a valid text channel.', ephemeral: true });
}

welcomeChannelId = channel.id;

await interaction.reply(`Welcome messages will now be sent in ${channel.name}`);
},
};

client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.get(welcomeChannelId);
if (!channel) return;

const embed = new EmbedBuilder()
.setColor(0x00AE86)
.setTitle(`Welcome ${member.user.username} to ${member.guild.name}!`)
.setDescription('Hope you\'ll have fun here!');

channel.send({ embeds: [embed] });
});
const { SlashCommandBuilder, EmbedBuilder, ChannelType, Client, GatewayIntentBits } = require('discord.js');

const client = new Client({ intents: [GatewayIntentBits.Guilds] });


let welcomeChannelId;

module.exports = {
data: new SlashCommandBuilder()
.setName('welcome')
.setDescription('Set the welcome channel for new members.')
.addChannelOption(option =>
option.setName('channel')
.setDescription('Channel where welcome messages will be sent')
.addChannelTypes(ChannelType.GuildText)
.setRequired(true)),

async execute(interaction) {
const channel = interaction.options.getChannel('channel');

if (!channel) {
return interaction.reply({ content: 'Please provide a valid text channel.', ephemeral: true });
}

welcomeChannelId = channel.id;

await interaction.reply(`Welcome messages will now be sent in ${channel.name}`);
},
};

client.on('guildMemberAdd', member => {
const channel = member.guild.channels.cache.get(welcomeChannelId);
if (!channel) return;

const embed = new EmbedBuilder()
.setColor(0x00AE86)
.setTitle(`Welcome ${member.user.username} to ${member.guild.name}!`)
.setDescription('Hope you\'ll have fun here!');

channel.send({ embeds: [embed] });
});
10 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Developer
DeveloperOP3mo ago
DiscordJS: 14.15.3 Node: 21.4.0
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Developer
DeveloperOP3mo ago
wdym
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Developer
DeveloperOP3mo ago
yes the client.on is
d.js docs
d.js docs3mo ago
:guide: Creating Your Bot: Event handling read more :guide: Creating Your Bot: Command handling read more
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Developer
DeveloperOP3mo ago
So, the client.on of welcome.js should be in a folder called "events" with only the client.on and the imports there?
Unknown User
Unknown User3mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server