My Welcome Message And Auto Role Doesn't Work

const Discord = require('discord.js')
const client = new Discord.Client()

client.on('guildMemberAdd', (member) => {
const welcomeChannelId = {
'1058088182861791282': '1058088182861791284'
}
const guild = client.guilds.cache.get("1058088182861791282")
member.guild.channels.cache.get(welcomeChannelId[member.guild.id]).send(`:wave: Welcome ${m} to **${guild}**! We are now at **${guild.memberCount} members**. Thank you for joining!`)
const MemberRoleAdd = member.guild.roles.cache.get('1058187823703916604')
member.roles.add(MemberRoleAdd)
})
const Discord = require('discord.js')
const client = new Discord.Client()

client.on('guildMemberAdd', (member) => {
const welcomeChannelId = {
'1058088182861791282': '1058088182861791284'
}
const guild = client.guilds.cache.get("1058088182861791282")
member.guild.channels.cache.get(welcomeChannelId[member.guild.id]).send(`:wave: Welcome ${m} to **${guild}**! We are now at **${guild.memberCount} members**. Thank you for joining!`)
const MemberRoleAdd = member.guild.roles.cache.get('1058187823703916604')
member.roles.add(MemberRoleAdd)
})
Solution:
I can tell you that you're using .cache.get which means that you're probably just not finding the channel or guild because it was never added to the cache. You should fetch the items you need
Jump to solution
12 Replies
24
24•2y ago
"does't work" what do you mean by this @AlphaMinedime?
Krish
Krish•2y ago
need more details
AlphaMinedime
AlphaMinedimeOP•2y ago
It does not show any error, or it does not send the message in the dizzy server.
24
24•2y ago
Have you tried to debug? There's a lot going on. Try to hardcode values in places and see if it works
AlphaMinedime
AlphaMinedimeOP•2y ago
No, sorry, idk how 😅
24
24•2y ago
I highly suggest using log statements or using the debugger built into visual studio code and looking for places that your code isn't doing what you think it's doing
Solution
24
24•2y ago
I can tell you that you're using .cache.get which means that you're probably just not finding the channel or guild because it was never added to the cache. You should fetch the items you need
AlphaMinedime
AlphaMinedimeOP•2y ago
Ok, I will. Thank you. Please keep this open just in case please.
24
24•2y ago
I don't control if this is open or not. Please make sure to mark the answer when you verify it is resolved
AlphaMinedime
AlphaMinedimeOP•2y ago
Ok! Ok, can someone help me with the console.error? it does not log anything
24
24•2y ago
I don't get what you mean
AlphaMinedime
AlphaMinedimeOP•2y ago
So, basically, I will show you.
client.on('guildMemberAdd', (member) => {
const welcomeChannelId = {
'1058088182861791282': '1058088182861791284'
}
try {
const guild = client.guilds.cache.get("1058088182861791282")
member.guild.channels.cache.get(welcomeChannelId[member.guild.id]).send(`:wave: Welcome ${member} to **${guild}**! We are now at **${guild.memberCount} members**. Thank you for joining!`)
const MemberRoleAdd = member.guild.roles.cache.get('1058187823703916604')
member.roles.add(MemberRoleAdd)
} catch (error) {
console.error(error)
}

})
client.on('guildMemberAdd', (member) => {
const welcomeChannelId = {
'1058088182861791282': '1058088182861791284'
}
try {
const guild = client.guilds.cache.get("1058088182861791282")
member.guild.channels.cache.get(welcomeChannelId[member.guild.id]).send(`:wave: Welcome ${member} to **${guild}**! We are now at **${guild.memberCount} members**. Thank you for joining!`)
const MemberRoleAdd = member.guild.roles.cache.get('1058187823703916604')
member.roles.add(MemberRoleAdd)
} catch (error) {
console.error(error)
}

})
So I will test it on a bot rq. Oh! It worked :D Thank you so much :)
Want results from more Discord servers?
Add your server