为什么会出现未定义的“发送”错误?

时间:2020-10-23 00:48:34

标签: javascript node.js discord.js

为什么出现未定义的“发送”错误?

에라다모르겠로한글지。

错误:无法读取未定义的이오류오류가왜的属性“发送”?

我的代码:

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) 

错误:无法读取未定义的属性“发送”

1 个答案:

答案 0 :(得分:0)

我认为您在这里遇到问题

const welcomeChannel = member.guild.channels.cache.find(channel => channel.topic === '#welcome')

将此更改为

const welcomeChannel = member.guild.channels.cache.find(channel => channel.name === 'welcome')

在此我将channel.topic更改为channel.name

这应该有效

我认为这是您出错的那一行,因为您没有明确告诉我这行