-1

At this moment I am trying to figure out why my 'Welcoming Message' isn't working at my own Discord server. I have been looking at several Stackoverflow topics and YouTube tutorials, I have read through the Discord.js documentation but I wasn't able to a proper solution. So, therefore I am trying to get my answers on this network via this topic.

The code I have so far:

client.on('guildCreate', (guild) => {
    let channelToSend;
    guild.channels.cache.forEach((channel) => {
        if(
            channel.type === "text" && 
            !channelToSend && 
            channel.permissionsFor(guild.me).has("SEND_MESSAGES")
        ) channelToSend = channel;
    });
    
    if(!channelToSend) return;

    let channelEmbed = new Discord.MessageEmbed()
    .setColor("RED")
    .setAuthor(`TEXT TEXT ${guild.name} TEXT!`)
    .setDescription("TEXT TEXT")
    .addField("Roles", "TEXT TEXT")

    channelToSend.send(channelEmbed).catch(e =>{
        if (e) {
            return;
        }});
})

I have absolutely no clue anymore why this isn't working. I also admit that I made the transition from Python to Javascript a month ago, so maybe I made an error somewhere?

I hope someone is able to help me out because I am clueless at the moment.

Thank you in advance.

Ahmad Habib
  • 2,053
  • 1
  • 13
  • 28
  • 1
    Just to be clear, are you getting an actual error? – Lioness100 Jul 14 '21 at 10:41
  • 1
    The guild is probably uncached. Use `guild.channels.fetch` instead – RishiC Jul 14 '21 at 10:51
  • Do you have [intents](https://stackoverflow.com/questions/64559390/none-of-my-discord-js-guildmember-events-are-emitting-my-user-caches-are-basica/64559391#64559391) enabled? – Tyler2P Jul 14 '21 at 10:56
  • Wait, you are saying your problem is with the welcoming message, but what do you exactly mean? Like is it the message for the Bot joining a Server or is it the message for a Member joining the server? – RishiMath Jul 14 '21 at 10:58
  • Hi, thank you all for the help. It is extremely appreciated. @Lioness100: About the error, I am not getting any errors in my terminal or in my discord channel. There is no message at all (also not the expected embed). – OrangeTiger Jul 14 '21 at 11:23
  • @RishiMath About the error, I am not getting any errors in my terminal or in my discord channel. There is no message at all (also not the expected embed). – OrangeTiger Jul 14 '21 at 11:23
  • @RishiC : I tried to edit it but without any luck. – OrangeTiger Jul 14 '21 at 11:23
  • @Tyler2P Yes sir, I got it activated. – OrangeTiger Jul 14 '21 at 11:23
  • I meant to ask, like was the message supposed to be for when the bot joins a server? Or it is for when a member joins a server? Since the guildCreate event is emitted when the bot joins a particular server. – RishiMath Jul 14 '21 at 11:26
  • @RishiMath Again, thank you for your quick reply. The message is supposed for everyone who joins the server. So, basically, I should change the guildCreate event? The code below written by Nigelrex actually works but I am still figuring out why, probably because of the 'guildMemberAdd' event? – OrangeTiger Jul 14 '21 at 11:30
  • Yeah, that is what it looks like in this case – RishiMath Jul 14 '21 at 11:32
  • It makes sense now I am reading through this. Thank you so much for the support @RishiMath and others! It is much appreciated. – OrangeTiger Jul 14 '21 at 11:37

1 Answers1

0

client.on("guildMemberAdd", (member) =>
  client.channels.cache.get("789830758331318273").send({
  //put your channel id in replace of "789830758331318273"
    embed: {
      title: "Joined",
      description: `\n <@${member.id}> joined the server. There are now \`${member.guild.memberCount}\` in the server \nWelcome <@${member.id}> :wave:`,
      color: config.color,
    },
  })
);
Rajaneesh.R
  • 24
  • 1
  • 4
  • 1
    Thank you so much for your help. Your code actually works. I am still wondering what I am doing wrong with my own code? Why isn't that working, probably because of the client.channels.cache.get("1234..") in your code? Again thank you so much for helping out. It is much appreciated. – OrangeTiger Jul 14 '21 at 11:25
  • 1
    @OrangeTiger if this code is producing then you were listening for the Wrong, since guildCreate event is Emitted when a bot joins a server, and guildMemberAdd event is Emitted when a new Member joins a server. – RishiMath Jul 14 '21 at 11:28