1
votes

hey im trying to get my discord bot make a greeting message when a new user is joinng the server.

here is my code.

bot.on('guildMemberAdd', member => {

const channel = member.guild.channels.find(channel => channel.name === "tvedes-gaming-room");
if(!channel) return;
channel.send(`Velkommen til, ${member}, Læs reglerne`)});

but i get this error.

 Cannot read property 'channels' of undefined
at DiscordClient.<anonymous> (C:\Users\Wind\Desktop\TvedeBot\bot.js:42:31)
at DiscordClient.emit (events.js:305:20)
at emit (C:\Users\Wind\Desktop\TvedeBot\node_modules\discord.io\lib\index.js:1580:14)
at DiscordClient.handleWSMessage (C:\Users\Wind\Desktop\TvedeBot\node_modules\discord.io\lib\index.js:1904:11)
at WebSocket.emit (events.js:305:20)
at Receiver.ontext (C:\Users\Wind\Desktop\TvedeBot\node_modules\ws\lib\WebSocket.js:841:10)
at C:\Users\Wind\Desktop\TvedeBot\node_modules\ws\lib\Receiver.js:536:18
at Receiver.applyExtensions (C:\Users\Wind\Desktop\TvedeBot\node_modules\ws\lib\Receiver.js:371:5)
at C:\Users\Wind\Desktop\TvedeBot\node_modules\ws\lib\Receiver.js:508:14
at Receiver.flush (C:\Users\Wind\Desktop\TvedeBot\node_modules\ws\lib\Receiver.js:347:3)

plz help me :-)

1
Looks like it should work. Possibly a server outage? Was Discord going offline when you tested this?Nathan Hawks
The code is correct, it should work. Are you sure this error is coming from this line?Gilles Heinesch
Yes. @gilles that is the only place in my code i have 'channels'Wind_dk
Makes no sense to me... could you try to log member and check if it's really the guildMemberObject?Gilles Heinesch
You are using the wrong tag, I created an edit for it to be moved to discord.io.PLASMA chicken

1 Answers

1
votes

You are using discord.io ( can be seen in the Error StackTrace ) you posted, the code you are using is for discord.js. You either need to find the discord.io equivalent code, or switch to discord.js. (Wich I would recommend due to the bigger community, wich makes it easier for beginners. )

If you want to start with discord.js: OpenSource Guide by the Community of discord.js