1
votes

got a message "TypeError: Cannot read property 'get' of undefined" whatever channel id I put in which is very annoying here is my code (very simple atm)

   bot.on('guildMemberAdd',user => {
        user.guild.channels.get("[existing channel ID]").send("SomeText")
    });

Am I doing it wrong? I tried with .find("name","channel_name") got the same error and tried with a console log as "cache" and got the awnser "undefined" as it is a key feature of my bot to be abble to post in a specific channel it's annoying... ^^' TY in advance for your help gonna keep trying to make it work^... ^^'

2

2 Answers

1
votes

You need to use .cache to access the guild channels so it'd be user.guild.channels.cache.get("[existing channel ID]").send("SomeText") in your case.

1
votes

You can test this :

bot.on('guildMemberAdd',user => {
     const channelWelcome = user.guild.channels.cache.get("[channel's ID]"
     channelWelcome.send("Your text")
});