Search code examples
node.jsdiscorddiscord.js

DiscordJS v14 guildMemberAdd Event doesn't send the embed


When I run my bot and someone joins, nothing happens.Why nothing happens?

Event file: `const { EmbedBuilder } = require('discord.js')

module.exports = { name: "guildMemberAdd",

/**
 * @param {GuildMember} member
 */
execute(member) {
    
    const wcChannel = member.guild.channels.fetch("1155899900161171586")


    console.log(`${member.name.toString()}` + "has joined!")
    

    const wcEmbed = new EmbedBuilder()
    .setTitle("Welcome")
    .setDescription(`${member.name.toString()}` + 'has joined the `SeaMystics`-Server!\n\n**Welcome!**')
    .setColor("#4ba511")
    .setTimestamp()

    wcChannel.send({embeds: [wcEmbed]})
}

}`

Main file: https://haste.l4zs.de/urahanipuv.typescript

Send a message to a channel, when someone joins


Solution

  • Your wcChannel is a Promise. You'll need to await it or get the channel from cache [suggested].


    Fetching

    const wcChannel = await member.guild.channels.fetch('1155899900161171586');
    // ...
    wcChannel.send({ embeds: [wcEmbed] });
    

    Get from cache

    const wcChannel = member.guild.channels.cache.get('1155899900161171586');
    // ...
    wcChannel.send({ embeds: [wcEmbed] });
    

    Source: GuildChannelManager