Home > OS >  I can't understand why does it not send Discord.js v13
I can't understand why does it not send Discord.js v13

Time:09-23

I can't understand why doesn't send the welcome message

Here's Code from index.js

client.on('guildMemberAdd', (member) => {
  let chx = db.get(`welchannel_${member.guild.id}`);
  if (chx === null) {
    return;
  }

  client.channels.cache.get(chx).send(`Welcome to ${message.guild.name}`);
});

Here's Code From channel.js module.exports = {

name: "channel",
  description: "Help Command",
  category: "Help",
  execute(client, message, args, Discord) {
    const db = require("quick.db")

    let channel = message.mentions.channels.first() //mentioned channel
    
    if(!channel) { //if channel is not mentioned
      return message.channel.send("Please Mention the channel first")
    }

    db.set(`welchannel_${message.guild.id}`, channel.id)
    
    const embed = new Discord.MessageEmbed()
        .setColor('#b5b5b5')
        .setTitle(`Channel set: ${channel.name} `)

    message.channel.send({ embeds: [embed] });
  }
}

CodePudding user response:

Basically, the reason is simple, you need to go to your dev portal then after choosing your bot/application just go to bot and you need to enable member intents Server Member Intent after that it should work, if it didn't just give it a 10 minute, then try again!

CodePudding user response:

The best way to ensure you get a channel object within the event is to use the guild property off the emitted member.

client.on("guildMemberAdd", (member) => {
      const { guild } = member;
      let chx = db.get(`welchannel_${member.guild.id}`);
      if(chx === null) {return}
        
      const channel = guild.channels.cache.get(chx);
      if (!channel) return;
      
      channel.send(`Welcome to ${message.guild.name}`)
         .catch(console.error);
})

You will need the Guild Member's intent enabled as stated in This Answer for the event to emit.

  • Related