0
votes

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));
});
1
If you run console.log(filteredChannels) after you declared the variable, what does it log? - Federico Grandi
It said Collection(0) [Map] {} - Lenin
Sorry for bad answer, i was on mobile and didnt read your code correctly. I am finding new answer. - doc. Chocholoušek
@Lenin it seems that the problem is in the filter function, you should try debugging that. Assuming you have at least one channel with one of those names, try putting console.log(channel.name) and console.log(channelNames.includes(channel.name)) in the code to see whether the channel is filtered correctly - Federico Grandi
size is a property not a method by the way (don’t call it).. - cherryblossom

1 Answers

0
votes

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"