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:
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] });
});