0

I've tried for a while but for some reason my Discord server welcome message isn't working. If anyone could help it would be much appreciated. Here's my code :

bot.on("guildMemberAdd", member => {
  const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')
  var serverIcon = message.guild.iconURL();
  const embed = new Discord.MessageEmbed()
  .setTitle("Welcome!")
  .setColor(3447003)
  .setDescription(`Welcome <${member.user.username}> to ${guild.name}!`)
  .addField(
    { name: ':D', value: 'Hope you enjoy your stay!'}
  )
  .setFooter("© Ninjabot 2020", bot.user.avatarURL)
  .setThumbnail(serverIcon)
  .setTimestamp()
  welcomeChannel.send({embed});
  })
  • What is the error message you are getting, if any? – SirArchibald Oct 30 '20 at 12:55
  • I'm not getting any error messages – Official Spoon Oct 30 '20 at 13:10
  • I believe your having the same problem as stated [here](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica). I suggest checking that post first. – Tyler2P Oct 30 '20 at 14:11
  • Okay so now I enabled Privelleged intents, I now recieve the error message saying that `var serverIcon = message.guild.iconURL();` message isn't defined guild isn't defined – Official Spoon Oct 30 '20 at 14:40
  • yes, because you are in the `guildMemberAdd` event. You don't have access to a `message` object here. Change `message.guild.iconURL();` to `member.guild.iconURL();` and it should work. – Worthy Alpaca Oct 30 '20 at 14:44
  • Sorry hehe I'm newish to this. I changed it to member but now I'm getting this error message: .setDescription(`Welcome <${member.user.username}> to ${guild.name}!`) ^ ReferenceError: guild is not defined – Official Spoon Oct 30 '20 at 14:49
  • same problem. You don't have a guild object here. You only have a member object. – Worthy Alpaca Oct 30 '20 at 15:03
  • How do I send the guild name then? – Official Spoon Oct 30 '20 at 15:13
  • same as with the iconURL, You need to use the `member` object to get to the `guild` object. Please read the [documentation](https://discord.js.org/#/docs/main/stable/class/GuildMember) – Worthy Alpaca Oct 30 '20 at 15:34
  • Thank you so much. It works now! Sorry I didn't check the documentation – Official Spoon Oct 30 '20 at 15:49

1 Answers1

0

Try replacing

welcomeChannel.send({embed});

with

welcomeChannel.send(${embed});

or

welcomeChannel.send(embed);

Example:

client.on('guildMemberAdd', member => {
    member.roles.add(member.guild.roles.cache.find(i => i.name === 'Among The Server'))
    
    const welcomeEmbed = new Discord.MessageEmbed()
    
    welcomeEmbed.setColor('#5cf000')
    welcomeEmbed.setTitle('**' + member.user.username + '** is now Among Us other **' + member.guild.memberCount + '** people')
    welcomeEmbed.setImage('https://myurl')
    
    member.guild.channels.cache.find(i => i.name === 'greetings').send(welcomeEmbed)
});
Tyler2P
  • 2,324
  • 26
  • 22
  • 31
Jimesh
  • 479
  • 5
  • 17
  • Well when I do that it says , expected and if I do ` welcomeChannel.send($,{embed});` then it doesn't make any difference. Now I'm going to try to do the embed without the `bot.on("guildMemberAdd", member => {` `const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')` and see if the embed works. – Official Spoon Oct 30 '20 at 13:08