Why is there an error called 'send' of undefined?
에라 모르겠다 한글로 써야지.
Error: Cannot read property 'send' of undefined 이런 오류가 왜 날까요?
MY CODE:
const discord = require('discord.js')
const client = new discord.Client()
const { prefix, token } = require("./config.json")
console.log("켜짐")
client.on('ready', () =>{
client.user.setActivity(",help")
})
client.on('message', (message) =>{
if(message.author.bot) return;
if(!message.content.startsWith(prefix)) return
else if(message.content.startsWith(`${prefix}help`)) {
const embed = new discord.MessageEmbed()
.setColor(`#adsjk2`)
.setDescription("도움말")
message.channel.send(embed)
}
})
client.on('guildMemberAdd', (member) => {
const welcomeChannel = member.guild.channels.cache.find(channel => channel.topic === '#welcome')
if(!welcomeChannel) return
if(welcomeChannel) {
welcomeChannel.send(`<@${member.id}>님 환영합니다!`)
return
} else {
return undefined
}
})
client.on('guildMemberRemove', (member) =>{
const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')
welcomeChannel.send(`<@${member.id}>님이 나가셨습니다...`)
return
})
client.login(token)
Error: Cannot read property 'send' of undefined
I think you are having the problem here,
const welcomeChannel = member.guild.channels.cache.find(channel => channel.topic === '#welcome')
change this to,
const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')
in this I changed channel.topic
to channel.name
this should work
I think this was the line you was having the error with as you didn't tell me the line specifically
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.