'Discord bot doesn't send welcome messages | JS

So I am stuck on the welcoming feature of my discord bot.

It doesn't send any message.

Here is the code for the welcome.js file:

module.exports = (client) => {
    client.on("guildMemberAdd", (member) => {
        
        const welcomechannel = '934868156399386676';
        const ruleschannel = '934877916041457774';

        const embed = new Discord.MessageEmbed()
        .setTitle(`New member has arrived!`)
        .setDescription(`Welcome to the server <@${member.id}>! Enjoy your stay and make sure to check our rules ${member.guild.channels.cache.get(ruleschannel).ToString()}! :slight_smile:`)
        .setColor('#0ed42a')
        .setTimestamp()
        client.channels.cache.getwelcomechannel.send(embed)
    })

here is the code for the index.js file:

onst { Client, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

const config = require("./config.json");
const welcome = require("./welcome.js");

client.once('ready', () => {
    console.log("Your bot is online!");


    welcome(client);
});

client.login(config.token); 


Solution 1:[1]

The problem is in this line:

client.channels.cache.getwelcomechannel.send(embed)

There are 2 issues, getwelcomechannel is not a function, and even if it was a function, you aren't calling it.

To fix this, you can use the .get() method on the collection of channels.

client.channels.cache.get(welcomechannel).send(embed)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Cool guy