Memag
Memag

Reputation: 17

Why does this make the bot crash?

bot.on('guildMemberAdd', member => {
    const welcomeembed = new Discord.RichEmbed()
            .setColor(0xfcdb03)
            .setTitle("Welcome")
            .addField("Welcome " + member + "** to our Discord Server!**", "Please verify yourself in " + message.guild.channels.get('723965000062074990'))
    member.guild.channels.get('723240170329079870').sendEmbed(welcomeembed); 
});

The bot isn't crashing when I use a regular message. Maybe I'm just using the Embed message wrong.

    Object.defineProperty(this, 'client', { value: message.client });
                                                           ^

TypeError: Cannot read property 'client' of undefined
    at new MessageEmbed (C:\Users\456899754\Desktop\node_modules\discord.js\src\structures\MessageEmbed.js:13:60)
    at Client.<anonymous> (C:\Users\456899754\Desktop\botfolder\bot.js:30:24)
    at Client.emit (events.js:310:20)
    at Guild._addMember (C:\Users\456899754\Desktop\node_modules\discord.js\src\structures\Guild.js:938:19)
    at GuildMemberAddHandler.handle (C:\Users\456899754\Desktop\node_modules\discord.js\src\client\websocket\packets\handlers\GuildMemberAdd.js:12:13)
    at WebSocketPacketManager.handle (C:\Users\456899754\Desktop\node_modules\discord.js\src\client\websocket\packets\WebSocketPacketManager.js:102:65)
    at WebSocketConnection.onPacket (C:\Users\456899754\Desktop\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:325:35)
    at WebSocketConnection.onMessage (C:\Users\456899754\Desktop\node_modules\discord.js\src\client\websocket\WebSocketConnection.js:288:17)
    at WebSocket.onMessage (C:\Users\456899754\Desktop\node_modules\ws\lib\EventTarget.js:103:16)
    at WebSocket.emit (events.js:310:20)```

Upvotes: 0

Views: 378

Answers (1)

Klaycon
Klaycon

Reputation: 11080

You need to set up your environment such that you can see errors. Otherwise, how can you expect to be able to fix any problems you encounter? If you're starting your bot with a batch file or something similar, edit it and add PAUSE on a new line to force the window to stay open after the process terminates. Otherwise, you can try having the node process output to a file - look up ways to do this.

The problem is likely referencing message.guild.channels.get('723965000062074990'). There is no message, you're in the guildMemberAdd event. Use member.guild instead.

bot.on('guildMemberAdd', member => {
  const welcomeembed = new Discord.RichEmbed()
    .setColor(0xfcdb03)
    .setTitle("Welcome")
    .addField("Welcome " + member + "** to our Discord Server!**", "Please verify yourself in " + member.guild.channels.get('723965000062074990'))
  member.guild.channels.get('723240170329079870').sendEmbed(welcomeembed); 
});

Upvotes: 1

Related Questions