I was watching YouTube tutorial about welcome messages. I copied whole code etc. When I’m using this code on discord.js v13 it doesn’t work. When I use this code on discord.js v12 everything works. Bot after joining new member send welcome message. On discord.js v13 bot didn’t say nothing and I don’t have any errors in terminal. Can someone help me with that? I’m beginner in codding and have only few tutorials knwededge. Please help.
Here’s index.js:
const Discord = require('discord.js');
const client = new Discord.Client({ intents: ["GUILDS", "GUILD_MESSAGES" , "GUILD_MESSAGE_REACTIONS" , "DIRECT_MESSAGE_REACTIONS" ] , partials: ["MESSAGE" , "CHANNEL" , "REACTION"] });
client.commands = new Discord.Collection();
const fs = require('fs');
const commandFiles = fs.readdirSync('./commands/').filter(file => file.endsWith('.js'))
for(const file of commandFiles){
const command = require(`./commands/${file}`)
client.commands.set(command.name, command)
}
const { prefix, token } = require('./config.json')
const welcome = require('./commands/welcome'); // Add This
client.once('ready', () => {
console.log('Ready.')
welcome(client) // Add This
})
client.on('message', message => {
if(!message.content.startsWith(prefix)||message.author.bot) return
const args = message.content.slice(prefix.length).split(/ +/)
const command = args.shift().toLowerCase()
if(command === 'ping'){
client.commands.get('ping').execute(message, args)
} else if(command === 'yt'){
client.commands.get('yt').execute(message, args)
} else if(command === 'purge'){
client.commands.get('purge').execute(message, args)
}
})
client.login(token)
Here’s welcome.js:
module.exports = (client) => {
// Welcome Message Command
const welcomechannelId = '' //Channel You Want to Send The Welcome Message
const targetChannelId = `` //Channel For Rules
client.on('guildMemberAdd', (member) => {
console.log(member)
const welocmemessage = ` <@${member.id}> Welcome To Our Server,
Please Read ${member.guild.channels.cache.get(targetChannelId).toString()}
Have A Nice Time!`
const channel = member.guild.channels.cache.get(welcomechannelId)
channel.send(welocmemessage)
})
// Leave Message Command
const leavechannelId = '' //Channel You Want to Send The Leave Message
client.on('guildMemberRemove', (member) => {
const leavemessage = `<@${member.id}> Just Left Server.`
const channel1 = member.guild.channels.cache.get(leavechannelId)
channel1.send(leavemessage)
})
}
Here’s config.json:
{
"token": "Your-Token",
"prefix": "+"
}