0

This is the welcome message and leave message I have set up with my discord bot. It is currently not working. It is not sending any errors. If you can help me out It would be appreciated. This is one of the bugs that I have not been able to fix. It may just be a simple error that I have made.

client.on('guildMemberAdd', member =>{
    const welcomemessage = new Discord.MessageEmbed()
        .setColor("#0099ff")
        .setDescription(`Welcome <@${member.user.id}> to the server! Please take the time to read <#758441509371641866> and <#758441426807423056>`);
    message.guild.member.cache.get(user.id).then(function(){
        let userjoinchat = message.guild.channels.cache.find(x => x.name === "welcome");
        userjoinchat.send(welcomemessage);
    })
})
client.on('guildMemberRemove', member =>{
    const byemessage = new Discord.MessageEmbed()
        .setColor("#0099ff")
        .setDescription(`Bye <@${member.user.id}>, I hope you enjoyed your stay!`);
    message.guild.member.cache.get(user.id).then(function(){
        let userleavechat = message.guild.channels.cache.find(x => x.name === "bye");
        userleavechat.send(byemessage);
    })
})
Brayden
  • 60
  • 7

1 Answers1

0

In your code you try to access the message object. The problem is that there is no message in the events you're using. Fortunatly that is an easy fix to make. All you have to do is access the member object, to which you do have access, instead.

I corrected your code here. I also stripped a few unneeded lines and added an extra check so you won't get an error if the channel cannot be found.

client.on('guildMemberAdd', member => {
    console.log("someone joined");
    const welcomemessage = new Discord.MessageEmbed()
        .setColor("#0099ff")
        .setDescription(`Welcome ${member} to the server! Please take the time to read <#758441509371641866> and <#758441426807423056>`);
    
    let userjoinchat = member.guild.channels.cache.find(x => x.name === "welcome");
    if (!userjoinchat) return;
    userjoinchat.send(welcomemessage);
})
client.on('guildMemberRemove', member => {
    console.log("someone left");
    const byemessage = new Discord.MessageEmbed()
        .setColor("#0099ff")
        .setDescription(`Bye ${member}, I hope you enjoyed your stay!`);

    let userleavechat = member.guild.channels.cache.find(x => x.name === "bye");
    if (!userleavechat) return;
    userleavechat.send(byemessage);
})

I have also added a console.log() at the beginning of each event, just so you can make sure they are actually emitting when someone joins or leaves. If thats not the case make sure you enable "privileged intents" in your bot developer settings.

Worthy Alpaca
  • 1,235
  • 1
  • 6
  • 13