So I made a bot that will send welcome messages in a channel to new members. My code is supposed to work because it didn't send any errors in my console, but my bot didn't send the welcome message.
I tried many things:
Made the embed an object (nope)
Made 4 long different codes (all not working)
Searched the web and watched some tuts (no error in the console but not sending)
I'm using discord.js@v12
Code:
client.on('guildMemberAdd', member => { // Finds the channel name from the array function channelNamesFilter(channel) { let channelNames = ['name', 'welcome', 'welcoming', 'greeting', 'general', 'hello']; if (channelNames.includes(channel.name)) { return true; } return false; } const welcome = new Discord.MessageEmbed() .setColor('#F2CC0D') .setTitle('Welcome To The Server!') .addFields({ name: member.nickname }, { name: '\n ', value: 'Make sure to visit the FAQ and Rules channel (if there are)!' }) .setImage(member.user.avatarURL) let filteredChannels = member.guild.channels.cache.filter(channelNamesFilter); filteredChannels.forEach(element => element.send(welcome));
}); 11 1 Answer
Ok I just solved it after like researching for more than 10 hours! I finally got it!
client.on('guildMemberAdd', member =>{ const channel = member.guild.channels.cache.find(channel => channel.name.includes('welcome')); if (!channel) return;
//send through channel
const welcomegreet = { color: 0xF2CC0D, title: `**WELCOME TO THE SERVER, ${member.user.tag} !!**`, description: `I hope you will enjoy it here! \n A place full of chaos and wonder!`, thumbnail: { url: member.user.avatarURL(), }, fields:[ { name: 'Need Help?', value: 'Please read the FAQ and Rules Channels (if there are)! \n Have Fun at the Server! CHEERS 🥂 !', inline: false }, { name: 'Join Me!', value: 'Do: `h.help` for entertainment and profanities!', inline: false } ], timestamp: new Date(),
};
//send through dm
const welcome = { color: 0xF2CC0D, title: `**WELCOME TO THE SERVER, ${member.user.tag} !!**`, description: `I hope you will enjoy it here! \n A place full of chaos and wonder!`, thumbnail: { url: member.user.avatarURL(), }, timestamp: new Date(),
};
member.send({ embed: welcomegreet });
channel.send({ embed: welcome });Thanks guys for trying to help me, even though It didn't get too close to the amswer. I tested this out and it worked splendidly! note: This only works if the channel has the word "welcome"