Javascript 欢迎消息| Discord.js的问题

Javascript 欢迎消息| Discord.js的问题,javascript,discord,discord.js,Javascript,Discord,Discord.js,我有一个欢迎消息机器人,每次有人加入时都会发送欢迎消息,但有时它会在控制台中抛出一个错误,说: member.guild.channels.cache.find(ch => ch.name === "・My guess is that if the channel is not found, that error occurs. The channel that wasn't found will return undefined. This code from the

我有一个欢迎消息机器人,每次有人加入时都会发送欢迎消息,但有时它会在控制台中抛出一个错误,说:

    member.guild.channels.cache.find(ch => ch.name === "・My guess is that if the channel is not found, that error occurs. The channel that wasn't found will return undefined. This code from the  DiscordJS website will check if the channel exists and if it doesn't, it won't run the rest of the function.

There is a much easier way to do what you are trying to do. Copy the ID of that channel and then get the channel in your code like this:

bot.on('guildMemberAdd', (member) => {
    const channel = member.guild.channels.cache.get('channel-id');
    channel.send('Welcome');
});

member.guild.channels.cache.find(ch=>ch.name==)・ 我的猜测是,如果未找到频道,则会发生错误。未找到的频道将返回未定义的频道。来自的此代码将检查该频道是否存在,如果不存在,则不会运行函数的其余部分。

有一种更简单的方法来执行您尝试执行的操作。复制该频道的ID,然后获取频道l在您的代码中如下所示:

也许试试这个

client.on('guildMemberAdd',member=>{

让welChannel=member.guild.channels.cache.find(ch=>ch.name==)・我可以把频道号放进去吗?