0
votes

I'm learning JavaScript with the Library Discord.js/Node.js and I'm building a Discord bot to exercise myself.

I'm trying to send a message to a new member of my discord server. The property I was looking for was .find, I didn't find it anywhere on the wiki of Discord.js and I've got an error that said Cannot read property 'get' of undefined.

So I decided to use a property that Ii found on the Wiki of Discord.js .Get. And I've got the same error. I don't know how to tell to the bot to send a message to the new user when he joins the server for the first time.

Here's my code:

bot.on("guildMemberAdd", MemberAdd => {
   MemberAdd.guild.channel.get("enter-leave").send("HI, welcome on my server.")
   console.log("enter");
});
2
just perusing the docs, i think 'channels' is the property you need? (you just have 'channel', which isn't a property of guild)Dan Oswalt
That's worked thanks, I'm feeling very dump for this error :).DataHearth

2 Answers

0
votes

The answer was that I've forgot the S for .channels. .channel was another property.

So my code is

bot.on("guildMemberAdd", MemberAdd => {

MemberAdd.guild.channels.find("name", "general").send("Bienvenu dans ma taverne mon chou :heart:.")

console.log("enter"); });
0
votes

for discord.js v12 you do:

bot.on("guildMemberAdd", MemberAdd => {
   let channel = MemberAdd.guild.channels.cache.find(channel => channel.name === "enter-leave")
   channel.send("HI, welcome on my server.")
   console.log("enter");
});