0

So I am coding a discord bot with discord.js and one of the features is that when a new user joins the server the bot sends a message. I am not making it an embed for now, I can do that myself later.

Here is my main welcome.js file specifically made for this feature:

module.exports = (client) => {
    const channelId = '868192573011931185' //welcome channel
    client.on('guildMemberAdd', (member) => {
        console.log(member.name)

        const message = `Hello <@${member.id}> and welcome to ${guild.name}! 
        Please verify through the Server Captcha Bot in your DMs, 
        then read the rules in <#868192573263605884> 
        and lastly pick your roles in <#868192573263605880>!`

        const channel = member.guild.channels.cache.get(channelId)
        channel.send(message)
    })
}

And in my index.js file I just imported the file, and added welcome(client).

But for some reason my code is not showing up in the Welcome channel... Any help will be appreciated.

Skulaurun Mrusal
  • 2,792
  • 1
  • 15
  • 29

3 Answers3

1

Check your intents are open and check this post for further information:

SpongeBed
  • 26
  • 1
  • 2
0

I don't know the context of your index.js but I suggest reading through this handy guide where they explain how you can handle events in seperate files.

Basically they loop through an events folder(where your welcome.js would be). Then they dynamically register the events that the client object receives to execute through those event files.

Link: Event handling.

0

In your code, instead of saying

const channel = member.guild.channels.cache.get(channelId)

try say:

const channel = Client.channels.cache.get(channelId)

Hope it works :)

Sham
  • 27
  • 5