0

I am making a Discord Bot that will greet users with a warm welcome, with no setup.

What I want it to do: I want it to find a channel with the name "welcome" and send a embed to it

What is actually does: It doesnt send anything. My help command uses the same thing but it doesn't work in the GuildMemberAdd event

Here is my code:

client.on("guildMemberAdd", (member) => {
  try {
  let embed = new Discord.MessageEmbed;
  embed.setTitle(`Welcome, ${member.username}!`)
  embed.setAuthor(message.author.username, message.author.avatarURL)
  embed.setDescription('We hope you enjoy your stay!')
  console.log(`New User "${member.user.username}" has joined "${member.guild.name}"` );
  const channel = member.guild.channels.cache.find(c => c.name === "welcome").id
  channel.send(embed);
  } catch(err) {
    console.log(err)
  }
FireyJS
  • 61
  • 1
  • 11

1 Answers1

1

A very small mistake in the code.

const channel = member.guild.channels.cache.find(c => c.name === "welcome").id
channel.send(embed);

If you read the code, const channel is basically the id of the channel and not the channel. You cannot send anything to an id.

Change it to:

const channel = member.guild.channels.cache.find(c => c.name === "welcome");
channel.send(embed);

Should work.

D J
  • 845
  • 1
  • 13
  • 27
  • It is probably since they don’t have guildMember events emitting instead of that – MrMythical Jun 26 '21 at 14:29
  • That would be hilarious, because if they want something to be sent when the guildMemberAdd event is emitted, they have to join the server or emit the event through code. – D J Jun 26 '21 at 14:31
  • Oops, My dumb self forgot to turn on Server Member intent. I also forgot to fix other stuff. Thanks for the help guys! – FireyJS Jun 26 '21 at 15:20
  • @FireyJS If this answer works for you, please mark it as the answer, or if you used some other method to solve your problem, you can post an answer yourself and mark it too! – D J Jun 26 '21 at 15:22